πŸ“– Cannot Read Property 'maps' of Undefined

Spatialized founder Jozef Sorocin
Jozef Soročin
Updated 07/13/2025

As we discussed in πŸ—ΊοΈ Creating a New Google Map , it's customary to provide a callback URL parameter in the initialization script:

<script async defer src="https://.../api/js?key=Aiza...&callback=initMap"></script>

The callback parameter ensures that the application logic where you call google.maps.XYZ is only run when the global window.google is properly initialized.

If window.google isn't initialized just yet, it's undefined. Thus, calling window.google.maps.XYZ is interpreted as undefined.maps which errors out and prints the message β€œCannot read property 'maps' of undefined.”

You are likely:

  • instantiating Google Maps classes like new google.maps.Map(...) or new google.maps.Marker(...)
  • or defining constants like const center = new google.maps.LatLng({...})

before google.maps is fully initialized.

Join 200+ developers who've mastered this! Get Complete Access β€” €19
Already a member? Sign in here