{"record":{"id":"7edb40c536f5a9a7","repo":"angular/components","slug":"cannot-interact-with-a-google-map-marker-before-it","errorCode":null,"errorMessage":"Cannot interact with a Google Map Marker before it has been initialized. Please wait for the Marker to load before trying to interact with it.","messagePattern":"Cannot interact with a Google Map Marker before it has been initialized\\. Please wait for the Marker to load before trying to interact with it\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/google-maps/map-advanced-marker/map-advanced-marker.ts","lineNumber":319,"sourceCode":"  private _combineOptions(): google.maps.marker.AdvancedMarkerElementOptions {\n    const options = this._options || DEFAULT_MARKER_OPTIONS;\n    return {\n      ...options,\n      title: this._title || options.title,\n      position: this._position || options.position,\n      content: this._content || options.content,\n      zIndex: this._zIndex ?? options.zIndex,\n      gmpDraggable: this._draggable ?? options.gmpDraggable,\n      gmpClickable: this._clickable ?? options.gmpClickable,\n      map: this._googleMap.googleMap,\n    };\n  }\n\n  /** Asserts that the map has been initialized. */\n  private _assertInitialized(): asserts this is {marker: google.maps.marker.AdvancedMarkerElement} {\n    if (typeof ngDevMode === 'undefined' || ngDevMode) {\n      if (!this.advancedMarker) {\n        throw Error(\n          'Cannot interact with a Google Map Marker before it has been ' +\n            'initialized. Please wait for the Marker to load before trying to interact with it.',\n        );\n      }\n    }\n  }\n}\n","sourceCodeStart":301,"sourceCodeEnd":327,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-advanced-marker/map-advanced-marker.ts#L301-L327","documentation":"MapAdvancedMarker wraps google.maps.marker.AdvancedMarkerElement which is created asynchronously once the map is available. _assertInitialized (called from _initialize and getAnchor) throws if the advancedMarker property is still undefined, preventing interaction with a marker that does not exist yet.","triggerScenarios":"Calling getAnchor or forcing _initialize before the AdvancedMarkerElement has been constructed (map not yet resolved, or required inputs like position not yet processed).","commonSituations":"Reading marker anchor/position immediately after adding the marker to a template; test assertions running before async init; using advanced markers without the required mapId or API version so creation fails upstream.","solutions":["Wait for the marker's initialization (e.g. the marker resolve promise) before calling getAnchor or other APIs.","Ensure the parent GoogleMap is fully loaded and a mapId is provided (required for AdvancedMarkerElement).","Defer marker interactions to after map idle/initialized events.","Check that a Maps API version supporting AdvancedMarkerElement is loaded."],"exampleFix":"// before\nconst anchor = this.marker.getAnchor();\n// after\nthis.map._resolveMap().then(() => {\n  const anchor = this.marker.getAnchor();\n});","handlingStrategy":"validation","validationCode":"if (!advancedMarkerComponent['advancedMarker']) {\n  throw new Error('AdvancedMarkerElement not ready; wait for the parent map to initialize.');\n}","typeGuard":"function isAdvancedMarkerReady(c: any): c is {advancedMarker: google.maps.marker.AdvancedMarkerElement} {\n  return c?.advancedMarker != null;\n}","tryCatchPattern":"try {\n  const anchor = marker.getAnchor();\n} catch (e) {\n  if (String((e as Error).message).includes('Marker before it has been initialized')) {\n    await map._resolveMap();\n  }\n}","preventionTips":["Provide a mapId on the parent GoogleMap (required for advanced markers).","Wait for the map to initialize before reading marker properties.","Verify a Maps API version supporting AdvancedMarkerElement is loaded.","Defer marker accessors until after map idle events."],"tags":["angular","google-maps","async-initialization","marker","dev-mode"],"backgroundTag":"not-initialized-yet","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}