{"record":{"id":"0d13d7b1e46c1787","repo":"angular/components","slug":"cannot-interact-with-a-google-map-groundoverlay-be","errorCode":null,"errorMessage":"Cannot interact with a Google Map GroundOverlay before it has been initialized. Please wait for the GroundOverlay to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map GroundOverlay before it has been initialized\\. Please wait for the GroundOverlay to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-ground-overlay/map-ground-overlay.ts","lineNumber":214,"sourceCode":"  }\n\n  private _watchForUrlChanges() {\n    this._url.pipe(takeUntil(this._destroyed)).subscribe(url => {\n      const overlay = this.groundOverlay;\n\n      if (overlay) {\n        overlay.set('url', url);\n        // Google Maps only redraws the overlay if we re-set the map.\n        overlay.setMap(null);\n        overlay.setMap(this._map.googleMap!);\n      }\n    });\n  }\n\n  private _assertInitialized(): asserts this is {groundOverlay: google.maps.GroundOverlay} {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (!this.groundOverlay) {\n        throw Error(\n          'Cannot interact with a Google Map GroundOverlay before it has been initialized. ' +\n            'Please wait for the GroundOverlay to load before trying to interact with it.',\n        );\n      }\n    }\n  }\n}\n","sourceCodeStart":196,"sourceCodeEnd":222,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-ground-overlay/map-ground-overlay.ts#L196-L222","documentation":"Thrown by MapGroundOverlay's dev-mode assertion when the underlying google.maps.GroundOverlay is still undefined. The overlay is created asynchronously after the map and overlay inputs (url, bounds) are available. Interacting before creation would hit an undefined object, so the library fails fast with this message.","triggerScenarios":"Calling getBounds(), getOpacity(), getUrl(), or getMeta/getUrl accessors (also _initialize paths) before the overlay's ngAfterContentInit has constructed google.maps.GroundOverlay — typically when invoked from ngOnInit or right after dynamic component creation.","commonSituations":"Reading overlay bounds/opacity immediately after component creation, conditional rendering that skips initialization, missing Google Maps API load so _initialize never completes, calling accessors in a parent's ngOnInit.","solutions":["Defer accessor calls until after view init or after the map is ready (subscribe to MapComponent.ready).","Check component readiness: only call getBounds/getOpacity/getUrl once the overlay has been initialized (e.g. after ngAfterViewInit of the host).","Verify the Google Maps script loaded; if _initialize never ran the overlay stays undefined.","Ensure required inputs (map, url, bounds) are set before the component initializes.","Use try-catch around accessor calls in dev to degrade gracefully."],"exampleFix":"// before\nconst bounds = this.groundOverlay.getBounds(); // throws if called too early\n// after\nthis.map.ready.subscribe(() => {\n  const bounds = this.groundOverlay.getBounds();\n});","handlingStrategy":"validation","validationCode":"if (!groundOverlayRef) throw new Error('GroundOverlay not ready');","typeGuard":"function isOverlayReady(o: MapGroundOverlay | undefined): o is MapGroundOverlay { return !!o; }","tryCatchPattern":"try {\n  const bounds = overlay.getBounds();\n} catch (e) {\n  if ((e as Error).message.includes('GroundOverlay')) {\n    // defer until map ready\n  } else { throw e; }\n}","preventionTips":["Gate overlay rendering on map ready event.","Call getters after ngAfterViewInit.","Ensure url/bounds inputs are bound before mount.","Don't read overlay state in the same change-detection pass as creation.","Check Maps API script load in console/network when errors repeat."],"tags":["angular","google-maps","lifecycle","initialization"],"backgroundTag":"component-accessed-before-initialization","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}