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();
...
});
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(); ... });