好吧,我已经阅读并尝试找出解决方案,但失败了......
我按照geoxmlv3:http://code.google.com/p/geoxml3/wiki/Usage
的说明进行操作这是该文件的引用:
<script type="text/javascript">
var myParser = new geoXML3.parser({afterParse: useTheData});
myParser.parse('my_geodata.kml');
function useTheData(doc) {
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc.placemarks.length; i++) {
doSomething;
}
};
</script>
根据文档,doc.placemarks应该工作并在KML文件中返回一个json的地标数组,遗憾的是这个'doc'甚至不存在(未定义),任何想法?
答案 0 :(得分:2)
如果您使用的是poly分支,“doc”就是一个数组。
function useTheData(doc) {
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc[0].placemarks.length; i++) {
doSomething;
}
};
我将修复文档中的示例。
答案 1 :(得分:0)
为什么不使用Google Maps API v3的KmlLayer? 将信息从KML文件映射到地图上很容易。
https://developers.google.com/maps/documentation/javascript/layers#KMLLayers