angular/components · error

Cannot interact with a Google Map Marker before it has been

Error message

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.

What it means

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.

Source

Thrown at src/google-maps/map-advanced-marker/map-advanced-marker.ts:319

  private _combineOptions(): google.maps.marker.AdvancedMarkerElementOptions {
    const options = this._options || DEFAULT_MARKER_OPTIONS;
    return {
      ...options,
      title: this._title || options.title,
      position: this._position || options.position,
      content: this._content || options.content,
      zIndex: this._zIndex ?? options.zIndex,
      gmpDraggable: this._draggable ?? options.gmpDraggable,
      gmpClickable: this._clickable ?? options.gmpClickable,
      map: this._googleMap.googleMap,
    };
  }

  /** Asserts that the map has been initialized. */
  private _assertInitialized(): asserts this is {marker: google.maps.marker.AdvancedMarkerElement} {
    if (typeof ngDevMode === 'undefined' || ngDevMode) {
      if (!this.advancedMarker) {
        throw Error(
          '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.',
        );
      }
    }
  }
}

View on GitHub (pinned to 0411926e7d)

Solutions

  1. Wait for the marker's initialization (e.g. the marker resolve promise) before calling getAnchor or other APIs.
  2. Ensure the parent GoogleMap is fully loaded and a mapId is provided (required for AdvancedMarkerElement).
  3. Defer marker interactions to after map idle/initialized events.
  4. Check that a Maps API version supporting AdvancedMarkerElement is loaded.

Example fix

// before
const anchor = this.marker.getAnchor();
// after
this.map._resolveMap().then(() => {
  const anchor = this.marker.getAnchor();
});
Defensive patterns

Strategy: validation

Validate before calling

if (!advancedMarkerComponent['advancedMarker']) {
  throw new Error('AdvancedMarkerElement not ready; wait for the parent map to initialize.');
}

Type guard

function isAdvancedMarkerReady(c: any): c is {advancedMarker: google.maps.marker.AdvancedMarkerElement} {
  return c?.advancedMarker != null;
}

Try / catch

try {
  const anchor = marker.getAnchor();
} catch (e) {
  if (String((e as Error).message).includes('Marker before it has been initialized')) {
    await map._resolveMap();
  }
}

Prevention

When it happens

Trigger: Calling getAnchor or forcing _initialize before the AdvancedMarkerElement has been constructed (map not yet resolved, or required inputs like position not yet processed).

Common situations: 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.

Related errors


AI-assisted analysis of angular/components@0411926e7d (2026-08-31). Data as JSON: /api/errors/7edb40c536f5a9a7. Report an issue: GitHub.