AdvancedMarker

Storybook

Open the AdvancedMarker story

AdvancedMarker places a google.maps.marker.AdvancedMarkerElement on the map. It shows the default red pin, a customised pin via Pin, or any HTML you pass as children.

Props

PropTypeDefaultDescription
positionLatLngInput | nullMarker position. Bindable: with draggable, use bind:position to track drags.
titlestringTooltip and accessible name.
zIndexnumber | nullStacking order.
draggablebooleanfalseLets the user drag the marker (gmpDraggable).
clickablebooleantrue when onClick is setMakes the marker clickable (gmpClickable).
collisionBehaviorgoogle.maps.CollisionBehaviorStringHow the marker behaves when it collides with others.
anchorLeftstring-50% (API default)CSS length-percentage that moves the anchor point horizontally.
anchorTopstring-100% (API default)CSS length-percentage that moves the anchor point vertically.
markergoogle.maps.marker.AdvancedMarkerElement | nullnullThe marker instance. Bindable: read it with bind:marker (for example to anchor an InfoWindow).
childrenSnippetCustom marker content, or a Pin.

LatLngInput is google.maps.LatLng | google.maps.LatLngLiteral | google.maps.LatLngAltitude | google.maps.LatLngAltitudeLiteral.

Event Props

PropTypeDescription
onClick(event: google.maps.marker.AdvancedMarkerClickEvent) => voidgmp-click
onDragStart(position: google.maps.LatLngLiteral | null) => voidgmp-dragstart
onDrag(position: google.maps.LatLngLiteral | null) => voidgmp-drag
onDragEnd(position: google.maps.LatLngLiteral | null) => voidgmp-dragend. Also updates bind:position.
onLoad(marker: google.maps.marker.AdvancedMarkerElement) => voidCalled once after the marker is created.

Usage

<script lang="ts">
	import { APIProvider, GoogleMap, AdvancedMarker, Pin } from 'svelte-google-maps-api';

	let position = $state({ lat: 35.6812, lng: 139.7671 });
</script>

<div style="height: 400px;">
	<APIProvider apiKey="YOUR_API_KEY">
		<GoogleMap center={{ lat: 35.6812, lng: 139.7671 }} zoom={13} mapId="DEMO_MAP_ID">
			<!-- Default pin, draggable -->
			<AdvancedMarker bind:position draggable title="Drag me" />

			<!-- Customised pin -->
			<AdvancedMarker position={{ lat: 35.6586, lng: 139.7454 }} title="Tokyo Tower">
				<Pin background="#0f766e" borderColor="#134e4a" glyphColor="white" glyphText="T" />
			</AdvancedMarker>

			<!-- Custom HTML -->
			<AdvancedMarker
				position={{ lat: 35.71, lng: 139.8107 }}
				onClick={() => alert('Skytree')}
			>
				<div class="badge">Skytree</div>
			</AdvancedMarker>
		</GoogleMap>
	</APIProvider>
</div>

<style>
	.badge {
		background: white;
		border-radius: 999px;
		padding: 4px 10px;
		box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
	}
</style>
svelte

Migrating from Marker

Marker (built on google.maps.Marker, deprecated since February 2024) was removed. Replace it with AdvancedMarker:

  • Set a mapId on GoogleMap; Advanced Markers do not render without one.
  • options.draggable becomes draggable, and options.label / options.icon become a Pin (glyphText, background, ...) or custom HTML children.
  • onClick receives an AdvancedMarkerClickEvent instead of a MapMouseEvent. Drag handlers receive the new position.

Notes

  • The map needs a mapId (use DEMO_MAP_ID for testing).
  • Children replace the default pin whenever they render an element or text. Content that appears later (for example behind an if block) is attached then, and the default pin returns when the children render nothing.
  • Inside MarkerClusterer, the marker is added to the clusterer instead of directly to the map.