{"record":{"id":"72ee970174de4164","repo":"angular/components","slug":"specified-anchor-does-not-implement-the-getanchor","errorCode":null,"errorMessage":"Specified anchor does not implement the `getAnchor` method. It cannot be used to open an info window.","messagePattern":"Specified anchor does not implement the `getAnchor` method\\. It cannot be used to open an info window\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/google-maps/map-info-window/map-info-window.ts","lineNumber":215,"sourceCode":"  ): void {\n    this.open(\n      {\n        getAnchor: () => advancedMarkerElement,\n      },\n      undefined,\n      content,\n    );\n  }\n\n  /**\n   * Opens the MapInfoWindow using the provided anchor. If the anchor is not set,\n   * then the position property of the options input is used instead.\n   */\n  open(anchor?: MapAnchorPoint, shouldFocus?: boolean, content?: string | Element | Text): void {\n    this._assertInitialized();\n\n    if ((typeof ngDevMode === 'undefined' || ngDevMode) && anchor && !anchor.getAnchor) {\n      throw new Error(\n        'Specified anchor does not implement the `getAnchor` method. ' +\n          'It cannot be used to open an info window.',\n      );\n    }\n\n    const anchorObject = anchor ? anchor.getAnchor() : undefined;\n\n    // Prevent the info window from initializing when trying to reopen on the same anchor.\n    // Note that when the window is opened for the first time, the anchor will always be\n    // undefined. If that's the case, we have to allow it to open in order to handle the\n    // case where the window doesn't have an anchor, but is placed at a particular position.\n    if (this.infoWindow.get('anchor') !== anchorObject || !anchorObject) {\n      // If no explicit content is provided, it is taken from the DOM node.\n      // If it is, we need to hide it so it doesn't take up space on the page.\n      this._elementRef.nativeElement.style.display = content ? 'none' : '';\n      if (content) {\n        this.infoWindow.setContent(content);\n      }","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/angular/components/blob/0411926e7d8ae06b32236ec1048a888cfad5abf2/src/google-maps/map-info-window/map-info-window.ts#L197-L233","documentation":"MapInfoWindow.open(anchor) requires the anchor to implement the MapAnchorPoint interface, whose only requirement is getAnchor(): google.maps.LatLng | google.maps.LatLngLiteral. The dev-mode check throws when a truthy anchor is passed but it lacks getAnchor, because the info window cannot derive its position from it.","triggerScenarios":"Calling infoWindow.open(someObject) where someObject is a plain object, a wrong component instance (e.g. a GoogleMap instead of a marker wrapper), or an element, instead of a MapMarker/MapAdvancedMarker or any object implementing getAnchor().","commonSituations":"Passing the native google.maps.Marker directly expecting the Angular wrapper API; passing a DOM element or a custom directive instance; API confusion after migrating between marker types; typos such as passing options as the first argument.","solutions":["Pass a component that implements MapAnchorPoint: MatGoogleMaps-derived markers like MapMarker or MapAdvancedMarker","If you must use a custom object, implement getAnchor(): google.maps.LatLng | google.maps.LatLngLiteral returning the position","If you only want to position the window at coordinates, call open() with no anchor and set the infoWindow's position input instead"],"exampleFix":"// before\ninfoWindow.open(nativeMarker); // no getAnchor\n// after\ninfoWindow.open(mapMarker); // Angular MapMarker implements getAnchor\n// or\ninfoWindow.position = {lat: 1, lng: 2};\ninfoWindow.open();","handlingStrategy":"validation","validationCode":"if (anchor && typeof (anchor as any).getAnchor !== 'function') {\n  throw new TypeError('anchor must implement MapAnchorPoint.getAnchor()');\n}","typeGuard":"function isMapAnchorPoint(x: unknown): x is MapAnchorPoint {\n  return !!x && typeof (x as any).getAnchor === 'function';\n}","tryCatchPattern":"try {\n  infoWindow.open(anchor);\n} catch (e) {\n  console.error('Invalid anchor passed to MapInfoWindow.open:', e);\n  infoWindow.position = fallbackPosition;\n  infoWindow.open();\n}","preventionTips":["Type anchor parameters as MapAnchorPoint, not any","Prefer Angular wrapper components (MapMarker, MapAdvancedMarker) over native markers","Use the position input for coordinate-only placement"],"tags":["angular","google-maps","info-window","api-misuse","type-mismatch"],"backgroundTag":"missing-required-method","analyzedSha":"0411926e7d8ae06b32236ec1048a888cfad5abf2","analyzedAt":"2026-08-31T11:58:23.400Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}