仓库文档里面不是有Demo吗,直接看就好了呀…… [mapbox/togeojson: convert KML and GPX to GeoJSON, without the fuss](https://link.segmentfault.com/?enc=IamvdkArjvL%2Bm6zN2T50fA%3D%3D.CwkD9yOq0850nbZOR%2Bi6x2GJSOVcRcVOC4h7U24j46QR1rill6q1xdnCe%2BK7aWl5cVO9Y3AZNDSASC%2B8KKODfA%3D%3D) * * * ## CLI Install it into your path with `npm install -g @mapbox/togeojson`. ~> togeojson file.kml > file.geojson ## Node.js Install it into your project with `npm install --save @mapbox/togeojson`. // using togeojson in nodejs var tj = require('@mapbox/togeojson'), fs = require('fs'), // node doesn't have xml parsing or a dom. use xmldom DOMParser = require('xmldom').DOMParser; var kml = new DOMParser().parseFromString(fs.readFileSync('foo.kml', 'utf8')); var converted = tj.kml(kml); var convertedWithStyles = tj.kml(kml, { styles: true }); ## Browser Download it into your project like wget https://raw.githubusercontent.com/mapbox/togeojson/master/togeojson.js $.ajax('test/data/linestring.kml').done(function(xml) { console.log(toGeoJSON.kml(xml)); }); toGeoJSON doesn't include AJAX - you can use [jQuery](https://link.segmentfault.com/?enc=MBhDOvSP8%2FDW1hLFglHrMQ%3D%3D.%2FW%2Ba0tdah%2FhXQ%2FjSRzfydpDfz0qjswNfHZN8NSmWRkQ%3D) for just AJAX.