Sometimes, we want to close all info windows in Google Maps API v3 and JavaScript.
In this article, we’ll look at how to close all info windows in Google Maps API v3 and JavaScript.
How to close all info windows in Google Maps API v3 and JavaScript?
To close all info windows in Google Maps API v3 and JavaScript, we can call the close
method.
For instance, we write
const latlng = new google.maps.LatLng(-34.397, 150.644);
let infoWindow = null;
//..
google.maps.event.addListener(marker, "click", () => {
infoWindow?.close();
infoWindow = new google.maps.InfoWindow();
//...
});
to call infoWindow?.close()
to close the info window when we click on a marker.
Then we create a new info window with
infoWindow = new google.maps.InfoWindow();
Conclusion
To close all info windows in Google Maps API v3 and JavaScript, we can call the close
method.