1

I am working from Google's Marker Clustering guide.

I just want to add a simple event to the markers inside a cluster.

Unfotunately, I cannot use marker.addListener('click', ... because no marker variable is declared.

Any idea how to add a click event to multiple markers using the same markup in the clustering guide?

Many thanks!

user2888697
  • 173
  • 3
  • 14
  • Modify the code to give you access to the marker (it does create one...) – geocodezip May 19 '17 at 23:24
  • 1
    possible duplicate of [Integrate Google Maps MarkerClusterer with infowindow](http://stackoverflow.com/questions/40047210/integrate-google-maps-markerclusterer-with-infowindow) – geocodezip May 19 '17 at 23:42

1 Answers1

4

As suggested in Integrate Google Maps MarkerClusterer with infowindow, a marker should be created with a click event:

var markers = locations.map(function(location, i) {
  var marker = new google.maps.Marker({
    position: location
  });
  google.maps.event.addListener(marker, 'click', function(evt) {
    //Add click event
  });
  return marker;
});

Here is the solution added to Google's Marker Clustering example: https://jsfiddle.net/9dmj3rkr/

Community
  • 1
  • 1
user2888697
  • 173
  • 3
  • 14
  • Thank you very much. I wasted 8 hours before reach you. One last problem I am facing, can I hide previous infoWindow when click on another marker? – Jitesh Meniya May 01 '19 at 12:57