For Google Maps V3, to check when google maps is fully loaded.
The trick is a combination of all the submissions on here
First you must create the map example:
let googleMap = new google.maps.Map(document.getElementById(targetMapId),
{
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
streetViewControl: false,
styles: [
{
featureType: "poi",
elementType: "labels",
stylers: [
{visibility: "off"}
]
}
],
});
Then you need to set a default location for it to load.. it can be anywhere
googleMap.setCenter({
lat: 26.12269,
lng: -80.130172
});
Then finally once it finishes loading the tiles for that location you can process code via the "tilesloaded" eent, this code can include re-centering the map, placing markers etc..
This ensures that the map is loaded before you do something with it
google.maps.event.addListenerOnce(googleMap, 'tilesloaded', function(){
// do something only the first time the map is loaded
});
Others have suggested the "idle" event as well, but I did not have much luck with that as it was hit or miss for me.
google.maps.event.addListenerOnce(googleMap, 'idle', function(){
// do something only the first time the map is loaded
});
Whereas when I used the "tilesloaded" , while I do get a quick blip then jump to the correct map view, it always works...so I went with the lesser of two evils
google.maps.event.addListenerOnce(map, 'tilesloaded', function() {
– Inexecution