Introducing a new way to review your PRs.

Read the announcement

visgl / react-google-maps

React components and hooks for the Google Maps JavaScript API

View on GitHub

19 documents · Updated Nov 2, 2026

docs / markers-and-info-windows

Markers, pins, and info windows

Markers place a point or custom visual on a map. Pins give supported markers a common visual style, while info windows show related content at a point or above a marker. This page explains these parts of the map overlay system and how they relate to geometric overlays.

Marker families

The library supports a legacy 2D marker, a richer 2D marker, and a 3D marker. Choose the family based on the map type and the amount of control needed over marker content.

Legacy 2D markers

The Marker component represents the established 2D marker model. It is suited to a marker that uses the Maps API visual options and needs common map events such as click, hover, or drag.

Marker does not render React children as marker content. Use AdvancedMarker when the marker itself must contain HTML, a custom control, or a Pin.

References: src/…/marker.tsx• L13-25 src/…/marker.tsx• L43-65 src/…/marker.tsx• L67-113

Advanced 2D markers

The AdvancedMarker component represents a 2D marker whose visual content can be a default pin, a Pin, or custom HTML. It places the marker at a geographic position and lets the application control its visual state with React content and CSS.

Advanced markers require a map that supports the advanced marker service. Their position normally uses the bottom center of the content as its geographic anchor. anchorLeft and anchorTop can move that anchor for custom shapes.

References: src/…/advanced-marker.tsx• L77-115 src/…/advanced-marker.tsx• L123-151 src/…/advanced-marker.tsx• L264-275 docs/…/advanced-marker.md• L8-13

3D markers

The Marker3D component places a marker in a Map3D. It supports ground or elevated positions and can show a default pin, a Pin, or custom image and SVG content.

The presence of onClick makes the 3D marker interactive. Without that handler, the marker remains a display element. This lets the same component describe both visual map features and user-selectable 3D features.

References: src/…/marker-3d.tsx• L41-75 src/…/marker-3d.tsx• L77-87 src/…/marker-3d.tsx• L127-137 src/…/marker-3d.tsx• L216-224

Pin variants

Pin is the shared marker visual for AdvancedMarker and Marker3D. It gives an application a standard pin shape with configurable color and glyph choices without requiring a complete custom marker design.

Pin host relationship

Pin must be a child of AdvancedMarker or Marker3D. The host supplies the map marker and the pin supplies its visual content. A Pin used outside either host has no marker to configure and is rejected.

The pin can use a built-in glyph, text, an image source, or React children for a custom glyph. When both a glyph property and children are supplied, the children provide the glyph content.

References: src/…/pin.tsx• L7-17 src/…/pin-legacy.tsx• L71-125 src/…/pin-modern.tsx• L73-128

API-version variants

Pin selects a compatible pin model after the marker library loads. Older Maps API versions use the legacy glyph form. Newer versions use the modern text or image glyph form.

The public component keeps these versions interchangeable by mapping old and new glyph props in both directions. An application can therefore use one Pin interface while the loaded Maps API determines the supported form.

References: src/…/pin.tsx• L38-51 src/…/pin.tsx• L53-80 src/…/pin-legacy.tsx• L21-24 src/…/pin-modern.tsx• L21-25

Marker interaction

Marker interaction connects map events to application state. The event model differs by marker family, but each family exposes a way to select a marker and, where supported, move it.

Event model

The legacy marker exposes map mouse events. The advanced 2D marker adds DOM and keyboard events for custom content, and it becomes clickable when an interaction handler is present unless clickable is set explicitly. A drag handler similarly enables dragging unless draggable is set explicitly.

The 3D marker uses its click handler to select the interactive 3D element. Its title provides rollover text for that interactive form. These defaults make event handlers part of the marker's interaction contract rather than only notification hooks.

References: src/…/marker.tsx• L13-20 src/…/advanced-marker.tsx• L66-75 src/…/advanced-marker.tsx• L282-337 src/…/marker-3d.tsx• L41-47 src/…/marker-3d.tsx• L127-128

Position and drag behavior

An application can update a marker's position from state. A moving marker therefore follows the same React state flow as other map overlays. Dragging is a 2D interaction; a marker at an altitude cannot be dragged.

When a marker controls an anchored info window, the marker reference must remain stable while its position changes. The info window then stays attached to the marker instead of being managed as a separate geographic point.

References: examples/…/moving-marker.tsx• L4-22 src/…/marker.tsx• L107-113 docs/…/advanced-marker.md• L209-221

Information-window anchoring

InfoWindow displays temporary content either at a map position or relative to a marker. An anchored window follows the marker and uses the marker as the source of its map position.

Anchored window lifecycle

The usual flow is to keep the window's open state in React, connect a marker ref to the anchor prop, and close that state from onClose. The map can close an info window through its close button, the Escape key, or marker changes, so onClose keeps application state aligned with the map.

An anchor value of null means that the marker reference is not ready. The window waits until the map and the anchor are available, then opens against that marker. The useAdvancedMarkerRef and useMarkerRef hooks provide the marker reference needed for this connection.

The following flow shows the relationship between marker state, interaction, and anchored content.

flowchart LR
  A[Marker rendered] --> B[Marker ref available]
  B --> C[User selects marker]
  C --> D[React opens InfoWindow]
  D --> E[InfoWindow anchors to marker]
  E --> F[Map or user closes window]
  F --> G[onClose updates React state]

References: src/…/info-window.tsx• L21-34 src/…/info-window.tsx• L180-243 docs/…/info-window.md• L59-100 examples/…/marker-with-infowindow.tsx• L8-29

Anchor alignment

An anchored info window normally opens above the top center of its marker. pixelOffset adds a fixed screen offset when the default placement does not match the marker visual.

Custom advanced-marker content can use a different anchor point. The marker's anchor settings and the info window's offset must describe the same visual point. Otherwise the window can appear beside the pin or above the wrong part of a custom shape.

An info window has the map's standard appearance and close behavior. When an application needs a fully custom bubble that is part of the marker visual, custom HTML inside AdvancedMarker is the more suitable model.

References: src/…/info-window.tsx• L186-225 docs/…/info-window.md• L125-150 docs/…/info-window.md• L32-38 docs/…/advanced-marker.md• L49-69

Change checklist

When these files or sections are changed, remember to consider these:

  • Changing a marker family can change the ref type and the event type expected by an anchored InfoWindow.
  • Changing Pin glyph props must preserve the mapping between legacy and modern Maps API versions.
  • Changing advanced-marker anchor rules must be checked with anchored info windows and custom marker content.
  • Adding or removing interaction handlers can change whether advanced or 3D markers are clickable or draggable.
  • Removing a marker while its info window is open must keep the onClose state path and anchor lifecycle in sync.

Important failure modes

TriggerConsequenceGuard
Pin is rendered outside AdvancedMarker or Marker3DNo marker can receive the pin contentKeep Pin directly inside a supported marker host
An InfoWindow receives anchor={null} while the marker ref is pendingThe window does not open yetRender or retain the anchor until the marker ref is ready
The map closes an info window without an onClose state updateReact state says the window is open while the map has closed itSet the open state to false from onClose
A custom marker uses an anchor point that does not match its visual shapeThe marker or anchored info window appears displacedSet marker anchor values and pixelOffset as one placement contract
A 3D marker has no click handlerThe marker is not the interactive 3D variantAdd onClick when the marker must accept selection

Key files

FileWhy to read it
src/…/marker.tsxDefines the legacy 2D marker and its event and position behavior.
src/…/advanced-marker.tsxDefines custom 2D marker content, anchoring, and interaction.
src/…/marker-3d.tsxDefines 3D marker placement, content, and interactive selection.
src/…/pin.tsxSelects the compatible pin variant and preserves the public pin model.
src/…/info-window.tsxDefines position-based and marker-anchored information windows.
examples/…/marker-with-infowindow.tsxShows the core marker selection and anchored window flow.
examples/…/moving-marker.tsxShows marker position driven by changing application state.
docs/…/advanced-marker.mdDescribes the advanced marker content and anchor contract.
docs/…/info-window.mdDescribes window placement, close events, and marker anchors.