我有一个包含地图所有标记的数组。即使使用MarkerClusterer,我也可以毫不费力地将它们放在地图上。 MarkerClusterer的addListener工作正常,但我只是无法获得标记addListener来触发事件。这是实际的代码:
function initializeMap(markerArray) {
var latlng = new google.maps.LatLng(0.0, 0.0);
var mapOptions = {
zoom: 2,
maxZoom: 21,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var length = markerArray.length,
element = null;
for (var i = 0; i < length; i = i + 2) {
var latlng = new google.maps.LatLng(markerArray[i],markerArray[i+1]);
var marker = new google.maps.Marker({
map: map,
position: latlng,
title:'Click to zoom'
});
markers.push(marker);
}
google.maps.event.addListener(marker, 'onclick', function() {
alert("I have been clicked");
});
var markerCluster = new MarkerClusterer(map, markers);
google.maps.event.addListener(markerCluster, 'clusterclick', function(cluster) {
alert("I have been clicked");
});
}