Right
I have found a solution. I added an additional property to the marker called "information", and then referred to it from the "addlistener" event "infowindow.setContent (this.info)".
Here is the updated code:
function setMarkers(branches, map) {
var marker = null;
var infowindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < branches.length; i++) {
branch = branches[i];
var myLatlngMarker = new google.maps.LatLng(branch[0], branch[1]);
var marker = new google.maps.Marker({
position: myLatlngMarker,
map: map,
title: branch[2],
info: branch[3],
icon: '<%=Icon%>'
});
google.maps.event.addListener(marker, 'click', function () {
infowindow.setContent(this.info);
infowindow.open(map, this);
});
bounds.extend(myLatlngMarker);
}
map.fitBounds(bounds);
}
source
share