在googlemaps v3 api中使用infowindow聚类标记

时间:2016-01-27 15:51:06

标签: javascript google-maps-api-3 markerclusterer

我无法让ClustererMarker工作。我希望标记在它们彼此靠近时聚类,我发现:

var mcOptions = {gridSize: 50, maxZoom: 15};
var mc = new MarkerClusterer(map, markers, mcOptions);

但是我不能让他们使用我的代码,要么所有标记都消失,要么只有一个可见(不是以正确的方式)。我希望有人可以帮我解决我的问题。

for (var i = 0; i < locations.length; i++) {
        var marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map
        });

       google.maps.event.addListener(marker, 'mouseover', (function (marker, i) {
            return function () {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
            }
        })(marker, i)); 
}   

1 个答案:

答案 0 :(得分:0)

var gmarkers = [];
    for (var i = 0; i < locations.length; i++) {
            var marker = new google.maps.Marker({
            position: new google.maps.LatLng(locations[i][1], locations[i][2]),
            map: map
            });

       google.maps.event.addListener(marker, 'mouseover', (function (marker, i) {
            return function () {
            infowindow.setContent(locations[i][0]);
            infowindow.open(map, marker);
            }
        })(marker, i)); 

gmarkers.push(marker);
}   

var markerCluster = new MarkerClusterer(map, gmarkers);