2012-12-26 39 views
1

嗯,我通過閱讀,並試圖找出解決方案,但不能標...geoxml3並沒有發揮作用

我跟着從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數組,不幸的是這「文檔」根本不存在(不確定),任何想法?

+0

[geoxml-V3](http://code.google.com/p/geoxml-v3/)和[geoxml3](http://code.google.com/p/geoxml3/ )是兩個不同的東西,看起來像你在問geoxml3。 – geocodezip

回答

2

如果您使用的是多分支, 「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

+0

非常感謝 –

0

爲什麼不使用Google Maps API v3的KmlLayer? 將信息從KML文件映射到地圖上很容易。

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

+0

我這樣做的原因是因爲我需要從KML中檢索數據。如果我沒有錯,地圖api不支持從地標檢索任何數據,除非您單擊或與標記交互。我想用標記放置標籤,但我不知道最好的方法。 –