Search code examples
javascriptgoogle-mapsgoogle-maps-api-3

Google Maps: Auto close open InfoWindows?


On my site, I'm using Google Maps API v3 to place house markers on the map.

The InfoWindows stay open unless you explicitly click the close icon. Meaning, you can have 2+ InfoWindows open at a time if you hover over the map marker.

Question: How do I make it so that only the current active InfoWindow is open and all other InfoWindows are closed? Meaning, no more than 1 InfoWindow will be open at a time?


Solution

  • 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.