Google Maps: Auto close open InfoWindows?
Solution 1:
There is a close() function for InfoWindows. Just keep track of the last opened window, and call the close function on it when a new window is created.
Solution 2:
alternative solution for this with using many infowindows: save prev opened infowindow in a variable and then close it when new window opened
var prev_infowindow =false;
...
base.attachInfo = function(marker, i){
var infowindow = new google.maps.InfoWindow({
content: 'yourmarkerinfocontent'
});
google.maps.event.addListener(marker, 'click', function(){
if( prev_infowindow ) {
prev_infowindow.close();
}
prev_infowindow = infowindow;
infowindow.open(base.map, marker);
});
}