Google Maps API V3 – add event listener to all markers?

In both Marker and MarkerWithLabel case, you might just as well use the this keyword to refer the object to which the event handler is attached:

google.maps.event.addListener(marker, 'click', function () {
   // do something with this marker ...
   this.setTitle('I am clicked');
});

this here is referring to the particular marker object.

Leave a Comment