Google Maps v3 MarkerClusterer not Clustering

你离开我真会死。 提交于 2019-11-29 11:40:20

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

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