steven-king / j586

Intermediate Interactive Media
17 stars 13 forks source link

Closing info windows on Google Maps #26

Closed steven-king closed 10 years ago

steven-king commented 10 years ago

If you need to close any info window when another window or marker is clicked, you need to do this:

Make your infowindow variable global by placing it outside the function at the top of your script. Then add infowindow.close() to the marker click event listener. See below.

var latlng = new google.maps.LatLng(-34.397, 150.644); var infowindow = null;

...

google.maps.event.addListener(marker, 'click', function() { if (infowindow) { infowindow.close(); } infowindow = new google.maps.InfoWindow(); ... });