Reputation: 13
I have a array containing all the markers of the map. I have no trouble placing them on the map even using MarkerClusterer with them. addListener for the MarkerClusterer works just fine, but I just simply can't get marker addListener to trigger the event. Here is the actual code:
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");
});
}
Upvotes: 1
Views: 3075
Reputation: 161404
You only have a click listener on your last marker (at least in the code you posted).
working markerclusterer example
Upvotes: 3