Sometimes, we want to resize a Google Map with JavaScript after it has loaded.
In this article, we’ll look at how to resize a Google Map with JavaScript after it has loaded.
How to resize a Google Map with JavaScript after it has loaded?
To resize a Google Map with JavaScript after it has loaded, we trigger the resize event in the idle event handler.
For instance, we write
google.maps.event.addListener(map, "idle", () => {
google.maps.event.trigger(map, "resize");
});
to call addEventListener to listen for the idle event.
In the idle event listener, we call trigger with map and 'resize' to resize the map after it has loaded.
Conclusion
To resize a Google Map with JavaScript after it has loaded, we trigger the resize event in the idle event handler.