How to check whether Google Maps is fully loaded with JavaScript?

Spread the love

Sometimes, we want to check whether Google Maps is fully loaded with JavaScript.

In this article, we’ll look at how to check whether Google Maps is fully loaded with JavaScript.

How to check whether Google Maps is fully loaded with JavaScript?

To check whether Google Maps is fully loaded with JavaScript, we listen to the idle event.

For instance, we write

google.maps.event.addListenerOnce(map, "idle", () => {
  // ...
});

to call addListenerOnce to add an idle event listener that run only once.

When the idle event is first triggered, that means the map is loaded or failed to load.

Conclusion

To check whether Google Maps is fully loaded with JavaScript, we listen to the idle event.

Leave a Reply

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