ClusterMarker with infoWindow

83 views
Skip to first unread message

bed777

unread,
Aug 15, 2011, 6:58:18 AM8/15/11
to google-maps-utility-library-v3
Hi guys,
this is my code:
function initialize() {
var latlng = new google.maps.LatLng(45.397, 15.644);
var myOptions = {
zoom: 5,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new
google.maps.Map(document.getElementById("map_canvas"), myOptions);

var i = 0;
for (i in m) {
var latlng = new google.maps.LatLng(m[i].latitude,
m[i].longitude);
marker = new google.maps.Marker({
position: latlng,
icon: m[i].icon
});
marker.commento = m[i].commento;
marker.dataOra = m[i].dataOra;

var contentString = '<div id="content"><h1>This is the content</
h1></div>';

var infowindow = new google.maps.InfoWindow({
content: contentString
});

infowindow.setPosition(latlng);
google.maps.event.addListener(marker, 'click', function() {
console.log(marker);
infowindow.open(map,marker);
});



markers.push(marker);
}

markerClusterer = new MarkerClusterer(map, markers, mcOptions);
}


The problem is: the infowindow added on every marker have the same
position and not the custom position that each marker must have.

Any Hints?
Thanks in advance.

Gary Little

unread,
Aug 16, 2011, 11:52:28 AM8/16/11
to google-maps-utility-library-v3
The problem is that you are defining only a single infowindow and,
after your loop, it takes on the position of the last marker in your
array. You either need to define a different infowindow for each
marker or dynamically change the position & content of a single
infowindow in the click handler for a marker. If the latter, put
infowindow.setPosition(this.getPosition()); in your click handler just
before you open the infowindow -- and define the infowindow once
outside your loop.

Gary

bed777

unread,
Aug 16, 2011, 1:48:31 PM8/16/11
to google-maps-utility-library-v3
Many thanks Gary.
Reply all
Reply to author
Forward
0 new messages