I can't get my markers to display different infowindows. The markers always display the content of the last "contentString".
I've read a few other posts but none of them seem to help.
This is the code:
function setMarkers(branches, map) {
var bounds = new google.maps.LatLngBounds();
var contentString = null;
var infowindow = null;
infowindow = new google.maps.InfoWindow();
for (var i = 0; i < branches.length; i++) {
var marker = null;
branch = branches[i];
var myLatlngMarker = new google.maps.LatLng(branch[0], branch[1]);
contentString = '<p>' + branch[3] + '</p>';
var marker = new google.maps.Marker({
position: myLatlngMarker,
map: map,
title: branch[2]
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(contentString);
infowindow.open(map, this);
});
bounds.extend(myLatlngMarker);
}
map.fitBounds(bounds);
}
Can anyone see what am I doing wrong?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…