I am currently doing this to create markers for my google map.
function createMarker(posn, title, html) {
var marker = new google.maps.Marker({ position: posn, title: title, draggable: false });
marker['infowindow'] = new google.maps.InfoWindow({ content: html });
infoWindows.push(marker['infowindow']);
google.maps.event.addListener(marker, "click", function () {
for (i = 0; i < infoWindows.length; i++) {
infoWindows[i].close();
}
this['infowindow'].open(map, this);
});
return marker;
}
im doesn't like the for loop, to close the tokens I know that something like this can be done using the same name:
if (infowindow) infowindow.close ();
the reason I use the code as above is because I am doing something like
markers[myPoint]['infowindow'].open(map, markers[myPoint]);else where, (myPoint is a number).
how can i avoid this for a loop to close open infowindows and do it in a glorious way?
source
share