geoxml3和地标不起作用

时间:2012-12-26 03:52:32

标签: javascript google-maps kml

好吧,我已经阅读并尝试找出解决方案,但失败了......

我按照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的地标数组,遗憾的是这个'do​​c'甚至不存在(未定义),任何想法?

2 个答案:

答案 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;
  }
};

我将修复文档中的示例。

working example

答案 1 :(得分:0)

为什么不使用Google Maps API v3的KmlLayer? 将信息从KML文件映射到地图上很容易。

https://developers.google.com/maps/documentation/javascript/layers#KMLLayers