Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding click event to KMLLayer Placemarks and Markers

How do i attach an onclick event to Placemarks specified in the KML file. Can event listeners be added to both google maps and google earth plugin? How would I go about this?

like image 641
Anirudh Ramanathan Avatar asked May 20 '11 10:05

Anirudh Ramanathan


1 Answers

In the Google Earth plugin...

google.earth.fetchKml(ge, href, function(kmlObject) {});
google.earth.addEventListener(kmlObject, 'click', function(event) {
    event.preventDefault();
    var kmlPlacemark = event.getTarget();
    alert(kmlPlacemark.getName());
});

In Google Maps API

var ctaLayer = new google.maps.KmlLayer('http://www.****.com/index.kml');
ctaLayer.setMap(map);
google.maps.event.addListener(ctaLayer, 'click', function(kmlEvent) {
    var text = kmlEvent.featureData.description;
    alert(text);
});
like image 196
Anirudh Ramanathan Avatar answered Oct 07 '22 21:10

Anirudh Ramanathan