Google Maps v3 MarkerClusterer not Clustering

后端 未结 1 1981
被撕碎了的回忆
被撕碎了的回忆 2020-12-19 17:22

I\'ve looked at the docs and can\'t figure it out. I\'m sure I\'m missing something stupid. No errors, but no clustering.

I tried to take the simple example from he

相关标签:
1条回答
  • 2020-12-19 18:21

    You aren't adding an array of google.maps.Marker objects to the MarkerClusterer.

    1. add a global array to store the google.maps.Markers in:

       var gmarkers=[];
      
    2. add the markers created by addMarker to that array:

       function addMarker(feature) {
          var marker = new google.maps.Marker({
              position: feature.position,
              icon: icons[feature.type].icon,  
              shadow: {
                  url: icons[feature.type].shadow,
                  anchor: new google.maps.Point(21, 32)
              },
              animation: google.maps.Animation.DROP,
              map: map
          });
          gmarkers.push(marker);
          google.maps.event.addListener(marker, "click", function () {
              infowindow.setContent(feature.data);
              infowindow.open(map,marker);
              map.setZoom(3);
              map.setCenter(marker.getPosition());
          });
      }
      
    3. add that array of google.maps.Markers to the MarkerClusterer (rather than the "features" array of objects).

      var mc = new MarkerClusterer(map, gmarkers, mcOptions);
      

    working example

    0 讨论(0)
提交回复
热议问题