Advanced Markers

AdvancedMarkerElement class

google.maps.marker.AdvancedMarkerElement class

Shows a position on a map. Note that thepositionmust be set for theAdvancedMarkerElementto display.

Note:Usage as a Web Component (e.g. using the custom<gmp-advanced-marker>HTML element, is only available in thev=betachannel).

Custom element:
<gmp-advanced-marker position= "lat,lng" title= "string" ></gmp-advanced-marker>

This class extends HTMLElement.

This class implements AdvancedMarkerElementOptions.

Access by callingconst {AdvancedMarkerElement} = await google.maps.importLibrary( "marker" ).SeeLibraries in the Maps JavaScript API.

AdvancedMarkerElement
AdvancedMarkerElement([options])
Parameters:
Creates anAdvancedMarkerElementwith the options specified. If a map is specified, theAdvancedMarkerElementis added to the map upon construction.
collisionBehavior
Type:CollisionBehavioroptional
content
Type:Nodeoptional
element
This field is read-only. The DOM Element backing the view.
gmpDraggable
Type:booleanoptional
map
Type:Mapoptional
position
HTML attribute:
  • <gmp-advanced-marker position= "lat,lng" ></gmp-advanced-marker>
  • <gmp-advanced-marker position= "lat,lng,altitude" ></gmp-advanced-marker>
title
Type:string
HTML attribute:
  • <gmp-advanced-marker title= "string" ></gmp-advanced-marker>
zIndex
Type:numberoptional
BetaaddEventListener
addEventListener(type, listener[, options])
Parameters:
  • type:stringA case-sensitive string representing the event type to listen for.
  • listener:EventListener|EventListenerObjectThe object that receives a notification. This must be a function or an object with the handleEvent method
  • options:boolean|AddEventListenerOptionsoptionalSeeoptions.Custom events only supportcaptureandpassive.
Return Value:void
Sets up a function that will be called whenever the specified event is delivered to the target. SeeaddEventListener
addListener
addListener(eventName, handler)
Parameters:
  • eventName:stringObserved event.
  • handler:FunctionFunction to handle events.
Return Value:MapsEventListenerResulting event listener.
Adds the given listener function to the given event name in the Maps Eventing system.
BetaremoveEventListener
removeEventListener(type, listener[, options])
Parameters:
Return Value:void
Removes an event listener previously registered with addEventListener from the target. SeeremoveEventListener
click
function(event)
Arguments:
This event is fired when theAdvancedMarkerElementelement is clicked.

Not available withaddEventListener()(usegmp-clickinstead).
drag
function(event)
Arguments:
This event is repeatedly fired while the user drags theAdvancedMarkerElement.

Not available withaddEventListener().
dragend
function(event)
Arguments:
This event is fired when the user stops dragging theAdvancedMarkerElement.

Not available withaddEventListener().
dragstart
function(event)
Arguments:
This event is fired when the user starts dragging theAdvancedMarkerElement.

Not available withaddEventListener().
Betagmp-click
function(event)
Arguments:
This event is fired when theAdvancedMarkerElementelement is clicked. Best used withaddEventListener()(instead ofaddListener()).

AdvancedMarkerElementOptions interface

google.maps.marker.AdvancedMarkerElementOptions interface

Options for constructing anAdvancedMarkerElement.

collisionBehavioroptional
Type:CollisionBehavioroptional
An enumeration specifying how anAdvancedMarkerElementshould behave when it collides with anotherAdvancedMarkerElementor with the basemap labels on a vector map.

Note:AdvancedMarkerElementtoAdvancedMarkerElementcollision works on both raster and vector maps, however,AdvancedMarkerElementto base map's label collision only works on vector maps.

contentoptional
Type:Nodeoptional
The DOM Element backing the visual of anAdvancedMarkerElement.

Note:AdvancedMarkerElementdoes not clone the passed-in DOM element. Once the DOM element is passed to anAdvancedMarkerElement,passing the same DOM element to anotherAdvancedMarkerElementwill move the DOM element and cause the previousAdvancedMarkerElementto look empty.

gmpDraggableoptional
Type:booleanoptional
Default:false
Iftrue,theAdvancedMarkerElementcan be dragged.

Note:AdvancedMarkerElementwith altitude is not draggable.

mapoptional
Type:Mapoptional
Map on which to display theAdvancedMarkerElement.The map is required to display theAdvancedMarkerElementand can be provided by settingAdvancedMarkerElement.mapif not provided at the construction.
positionoptional
Sets theAdvancedMarkerElement's position. AnAdvancedMarkerElementmay be constructed without a position, but will not be displayed until its position is provided - for example, by a user's actions or choices. AnAdvancedMarkerElement's position can be provided by settingAdvancedMarkerElement.positionif not provided at the construction.

Note:AdvancedMarkerElementwith altitude is only supported on vector maps.

titleoptional
Type:stringoptional
Rollover text. If provided, an accessibility text (e.g. for use with screen readers) will be added to theAdvancedMarkerElementwith the provided value.
zIndexoptional
Type:numberoptional
AllAdvancedMarkerElements are displayed on the map in order of their zIndex, with higher values displaying in front ofAdvancedMarkerElements with lower values. By default,AdvancedMarkerElements are displayed according to their vertical position on screen, with lowerAdvancedMarkerElements appearing in front ofAdvancedMarkerElements farther up the screen. Note thatzIndexis also used to help determine relative priority betweenCollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITYAdvanced Markers. A higherzIndexvalue indicates higher priority.

AdvancedMarkerClickEvent class

google.maps.marker.AdvancedMarkerClickEvent class

This event is created from clicking an Advanced Marker. Access the marker's position withevent.target.position.

This class extends Event.

Access by callingconst {AdvancedMarkerClickEvent} = await google.maps.importLibrary( "marker" ).SeeLibraries in the Maps JavaScript API.

PinElement class

google.maps.marker.PinElement class

APinElementrepresents a DOM element that consists of a shape and a glyph. The shape has the same balloon style as seen in the defaultAdvancedMarkerElement.The glyph is an optional DOM element displayed in the balloon shape. APinElementmay have a different aspect ratio depending on itsPinElement.scale.

Note:Usage as a Web Component (e.g. usage as an HTMLElement subclass, or via HTML) is not yet supported.

This class extends HTMLElement.

This class implements PinElementOptions.

Access by callingconst {PinElement} = await google.maps.importLibrary( "marker" ).SeeLibraries in the Maps JavaScript API.

PinElement
PinElement([options])
Parameters:
background
Type:stringoptional
borderColor
Type:stringoptional
element
This field is read-only. The DOM Element backing the view.
glyph
Type:string|Element|URLoptional
glyphColor
Type:stringoptional
scale
Type:numberoptional
BetaaddEventListener
addEventListener(type, listener[, options])
Parameters:
Return Value:void
This function is not yet available for usage.
BetaremoveEventListener
removeEventListener(type, listener[, options])
Parameters:
Return Value:void
Removes an event listener previously registered with addEventListener from the target. SeeremoveEventListener

PinElementOptions interface

google.maps.marker.PinElementOptions interface

Options for creating aPinElement.

backgroundoptional
Type:stringoptional
The background color of the pin shape. Supports any CSScolor value.
borderColoroptional
Type:stringoptional
The border color of the pin shape. Supports any CSScolor value.
glyphoptional
Type:string|Element|URLoptional
The DOM element displayed in the pin.
glyphColoroptional
Type:stringoptional
The color of the glyph. Supports any CSScolor value.
scaleoptional
Type:numberoptional
Default:1
The scale of the pin.