Skip to content

Marker (gm-marker)


The Marker is the most used component of the library (and Google Maps).

Simple Use (demo)

html
<template>
  <div style="height: 500px">
    <gm-map>
      <gm-marker :position="{ lat: 0, lng: 0 }" />
    </gm-map>
  </div>
</template>

<script setup lang="ts">
import { gmMap, gmMarker } from 'v3-gmaps';
</script>

Props

PropsTypeDefaultDescription
clickableboolean-Whether the marker receives mouse and touch events.
draggableboolean-Whether the marker can be dragged.
positionGmPosition-Sets the marker position.
titlestring-Rollover text.
visibleboolean-Whether the marker is visible.
zIndexnumber-Vertical layer to use for this marker.
pinGmPin-Customizes the marker appearance with the pin style.
optionsgoogle.maps.marker. AdvancedMarkerElementOptions-Google Maps AdvancedMarkerElementOptions interface

Pin Customization

The pin property allows fully customizing the marker appearance:

html
<!-- Basic text glyph -->
<gm-marker
  :position="position"
  :pin="{
    background: '#4285F4',
    borderColor: '#000000',
    glyphColor: '#FFFFFF',
    scale: 1.5,
    glyph: 'A'
  }"
/>

<!-- Image glyph -->
<gm-marker
  :position="position"
  :pin="{
    background: '#FBBC04',
    scale: 1.5,
    glyph: imageUrl
  }"
/>

<!-- SVG glyph -->
<gm-marker
  :position="position"
  :pin="{
    background: '#34A853',
    scale: 1.5,
    glyph: '<svg viewBox="0 0 24 24"><path fill="#FFFFFF" d="M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z"/></svg>'
  }"
/>

Slots

You can create completely custom markers using the default slot:

html
<gm-marker :position="{ lat: -33.9, lng: 151.1 }">
  <div class="custom-marker-container">
    <img src="/path/to/image.png" alt="Custom marker" />
    <div class="marker-label">My Label</div>
  </div>
</gm-marker>

Events

EventTypeDescription
clickGmPositionThis event is fired when the Marker is clicked.
contextmenuGmPositionThis event is fired when the DOM contextmenu event is fired on the Marker.
dblclickGmPositionThis event is fired when the Marker is double clicked.
dragGmPositionThis event is repeatedly fired while the user drags the Marker.
dragendGmPositionThis event is fired when the user stops dragging the Marker.
dragstartGmPositionThis event is fired when the user starts dragging the Marker.
mountedAdvancedMarkerElementOn mounted the component will emit the Google Maps object it represents.
mousedownGmPositionThis event is fired for a mousedown on the Marker.
mouseoutGmPositionThis event is fired when the mouse leaves the area of the Marker.
mouseoverGmPositionThis event is fired when the mouse enters the area of the Marker.
mouseupGmPositionThis event is fired for a mouseup on the Marker.
position_changedGmPositionThis event is fired when the Marker position property changes.
rightclickGmPositionThis event is fired for a rightclick on the Marker.
unmountedAdvancedMarkerElementOn unmounted the component will emit the Google Maps object it represents.

Notes

  • gm-marker is based on the Google Maps AdvancedMarkerElement which requires your map to have a valid mapId.
  • The mounted and unmounted events return the Google Maps AdvancedMarkerElement object. If you use the @types/google.maps package, it will be typed as google.maps.marker.AdvancedMarkerElement.

Released under the MIT License.