use*_*815 8 javascript kml google-maps-api-3
将侦听器附加到KML层:
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);
});
Run Code Online (Sandbox Code Playgroud)
KML文件有效(通过验证api检查),您可以在此处找到它.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>
Run Code Online (Sandbox Code Playgroud)
当点击谷歌地图对象中的地标时返回正确的ID,但有时大约50%的时间obj.featuredData.id是null(ZERO_RESULTS状态在status字段中).我尝试过不同的数据集(从100点到1000点),但没有用.我也尝试过lat,lng的不同精度.
您可能已经达到该页面上列出的限制之一:https://developers.google.com/kml/documentation/mapsSupport?hl =en
每个文件最多 1000 个功能可能会令您烦恼。
| 归档时间: |
|
| 查看次数: |
1854 次 |
| 最近记录: |