Attaching a listener to a KML layer:
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); });
The KML file is valid (verified using api check), you can find it here . Each label in XML has an id attribute, for example:
<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>
When you click on the label in the google map object, the correct identifier is returned, but sometimes about 50% of the time obj.featuredData.id is null ( ZERO_RESULTS status is in the status field). I tried different data sets (from 100 to 1000), but this does not help. In addition, I tried different settings for lat, lng.
javascript google-maps-api-3 kml
user1570815
source share