javascript 获取 JSON 格式的 Google Map KML 数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8172184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get Google Map KML data in JSON format
提问by Camsoft
Is there a way to get the KML file attached to this Google Mapin JSON format instead of XML?:
有没有办法以JSON 格式而不是 XML 格式将 KML 文件附加到此Google 地图?:
I'm currently writing an app that needs to load this KML data. I would prefer that it's in JSON format. Is there a way of getting it in this format?
我目前正在编写一个需要加载此 KML 数据的应用程序。我更喜欢它是 JSON 格式。有没有办法以这种格式获取它?
采纳答案by yalestar
Since KML is just a flavor of XML, you could use any XML to JSON converter, of which there are many.
由于 KML 只是 XML 的一种形式,您可以使用任何 XML 到 JSON 转换器,其中有很多转换器。
Here's one that's been around for a few years: http://www.thomasfrank.se/xml_to_json.html
这是一个已经存在了几年的:http: //www.thomasfrank.se/xml_to_json.html
回答by ackuser
I was trying to convert KML files to JSON and it was the most useful tool I found to do it programmatically
我试图将 KML 文件转换为 JSON,这是我发现以编程方式完成的最有用的工具
https://github.com/mapbox/togeojson#using-it-as-a-console-utility
https://github.com/mapbox/togeojson#using-it-as-a-console-utility
It is with nodejs, you should do something like that in the cli
它是用 nodejs,你应该在 cli 中做类似的事情
togeojson file.kml > file.geojson
togeojson file.kml > file.geojson
Then, you can pass it into a json quite easy
然后,你可以很容易地将它传递给一个 json
Anyway, hope this help
无论如何,希望这有帮助