close other infowindows nicely.
Posted
by
raklos
on Stack Overflow
See other posts from Stack Overflow
or by raklos
Published on 2011-02-24T21:54:24Z
Indexed on
2011/02/24
23:25 UTC
Read the original article
Hit count: 188
JavaScript
|google-maps
Im 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 not happy with the for loop, for closing the markers, i know something similar to this can be done by using one refernce:
if (infowindow) infowindow.close();
the reason I am using code like 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 loop to close open infowindows and do it the nice way?
© Stack Overflow or respective owner