2012-08-02 82 views
8

附加監聽到KML層:谷歌地圖KML地標層的單擊事件返回ZERO_RESULTS

var layer = new google.maps.KmlLayer('http://sites.google.com/site/kmlprototypes/kmls/temp.kml?dc_=' + Math.random(), 
{suppressInfoWindows:true,preserveViewport:true}); 

layer.setMap(map); 

google.maps.event.addListener(layer, 'click', function (obj) { 
    alert(obj.featureData.id); 
}); 

KML文件是有效的(通過驗證API檢查),你會發現它here。在XML每個地標具有id屬性,如:

<Placemark id="46"> 
    <Style> 
    <IconStyle> 
     <Icon> 
     <href> 
      <![CDATA[http://chart.apis.google.com/chart?chf=bg,s,EAF7FE02&chxt=y&chbh=a,4,4&chs=48x48&cht=bvg&chco=FF0000,0000FF&chds=20,9048.00,0,9048.00&chd=t:8149.00|9048.00]]> 
     </href> 
     </Icon> 
    </IconStyle> 
    </Style> 
    <Point> 
    <coordinates>30.49566650390625,50.721378326416016</coordinates> 
    </Point> 
</Placemark> 

當在谷歌地圖對象地標點擊返回權ID,但有時時obj.featuredData.id約50%是nullZERO_RESULTS狀態是在status字段)。我嘗試了不同的數據集(從100點到1000),但它沒有幫助。我也嘗試過不同的lat,lng精度。

+0

請只做[自定義標記(「圖表」)](https://maps.google.com/maps?q=http:%2F%2Fsites.google.com%2Fsite%2Fkmlprototypes%2Fkmls%2Ftemp。 kml&hl = en&gl = us&t = m&z = 9&iwloc = lyrftr:kml:cu4G8yGAGMgyJQA_oDPu6YymLEiMB,ga181ff8803d8d1b7_886,50.483726,30.091553,0,-32)會出現問題嗎? – geocodezip 2012-08-03 01:18:57

+2

看起來像您的KML包含太多的自定義標記。 [Here](http://www.geocodezip.com/geoxml3_test/v3_geoxml3_kmltest_linktoB.html?lat=50.501460&lng=30.404131&zoom=13&type=m&filename=http://www.geocodezip.com/geoxml3_test/kmlprototypes_temp_kml.xml)它是使用geoxml3渲染(需要一段時間渲染)。如果您隱藏這些標記(單擊隱藏按鈕),然後顯示KmlLayer,您會看到默認藍色標記和自定義標記的組合。 – geocodezip 2012-08-03 08:40:50

回答