2012-08-02 122 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

回答