π Cannot Read Property 'maps' of Undefined

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(...)
ornew 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