Detect InfoWindow Being Closed – Google Maps V3 API
If you’re including a map on your website using the Google Maps V3 API there’s a high chance you’ll be including overlaid markers and infowindows that are related to these markers. Adding the markers is simple enough, as is getting the infowindows to open upon clicking them, but what if we need to detect when an infowindow is closed?
I came across this scenario earlier today where I need to set the map back to a certain lat/lon position upon the infowindow being closed. After a bit of research and playing around I figured it out to be something like so:
google.maps.event.addListener(infowindow, 'closeclick', function() { alert("I'm Closed"); });
Simply add the above to within the map initialisation function and you’ll now be able to perform actions upon infowindows being closed.
Note: You’ll need to change ‘infowindow’ in the above snippet to the variable name assigned to the infowindows in your own code.
thank u sir, it is just what i needed
That’s exactly what I was looking for. Thanks!
Sweeeet! I was just playing around with this, nice tip ;)