Categories
JavaScript Answers

How to resize a Google Map with JavaScript after it has loaded?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *