Google Maps Multiple markers with the exact same location Not working

[亡魂溺海] 提交于 2019-11-27 12:57:41

You need to :

  1. create the marker clusterer first.
  2. add the markers to the MarkerClusterer (and format your code so it is easier to read...).

    function createMarker(latlng,text) {
      var marker = new google.maps.Marker({
        position: latlng,
        map: map
      });
    
      ///get array of markers currently in cluster
      var allMarkers = mc.getMarkers();
    
      //check to see if any of the existing markers match the latlng of the new marker
      if (allMarkers.length != 0) {
        for (i=0; i < allMarkers.length; i++) {
          var existingMarker = allMarkers[i];
          var pos = existingMarker.getPosition();
    
          if (latlng.equals(pos)) {
            text = text + " & " + content[i];
          }                   
        }
      }
    
      google.maps.event.addListener(marker, 'click', function() {
        infowindow.close();
        infowindow.setContent(text);
        infowindow.open(map,marker);
      });
      mc.addMarker(marker);
      return marker;
    }
    

working example

Same example i have modified and showing data in text instead of info window, if it is one it will show in one div, if it is more than one then it will show in carousel... Please check the example...

Clustered Maps Multiple markers with the exact same location

Example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!