Skip to main content

Marker

The Marker object displays a single marker on the map.

Marker extends Layer.

Example usage​

const map = G.map('map', { apiKey: 'my-api-key', center: { latitude: 48.864716, longitude: 2.3522 } });
map.load().then(() => {
const marker = G.marker({
latitude: 48.9,
longitude: 2.4,
map: map,
title: 'My Marker',
});
});

Creating the Marker object​

G.marker(options?: MarkerOptions): Marker

There are a few ways that you can setup the Marker object.

No parameters.

G.marker(): Marker

const marker = G.marker();

Pass the marker options.

G.marker(options: MarkerOptions): Marker

ParameterTypeRequiredDescription
optionsMarkerOptionsYesThe options.
const marker = G.marker({position: [48.9, 2.4]});

Set the location only.

G.marker(position: LatLngValue): Marker

ParameterTypeRequiredDescription
positionLatLngValueYesThe latitude/longitude value.
const marker = G.marker([48.9, 2.4]);

Set the location and the options.

G.marker(position: LatLngValue, options: MarkerOptions): Marker

ParameterTypeRequiredDescription
positionLatLngValueYesThe latitude/longitude value.
optionsMarkerOptionsYesThe options.
const marker = G.marker([48.9, 2.4], {title: 'Marker title'});

Pass an existing Marker object.

G.marker(object: Marker): Marker

In this case the Marker object is simply returned.

ParameterTypeRequiredDescription
objectMarkerYesA Marker object.
const marker = G.marker(markerObject);

MarkerLabel type​

The MarkerLabel type is an object that represents the label value for the marker. You can either pass a string for the label value, or an object.

The MarkerLabel type is the same as the Google Maps MarkerLabel interface.

OptionTypeDefaultDescription
classNamestringThe class attribute value for the label.
colorstringblackThe label text color
fontFamilystringThe label text font family
fontSizestring or number14pxThe label text font size. If it's a number then "px" is added to the end of it.
fontWeightstringThe label text font weight
textstring or numberThe label text. A number is converted to a string.

Custom data type​

You can attach an object of data to the marker object to hold some custom data. An example usage would be to include some content that you want to show in a popup when a marker is clicked.

The CustomData type represents this data. Essentially it's an object that can hold any type of data

type CustomData = {
[key: string]: any;
}

Marker options​

Type MarkerOptions

OptionTypeDefaultDescription
anchorPointPointValueThe offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor.
cursorstringpointerThe cursor type to show on hover.
dataCustomDataAn optional object to hold custom data to attach to the marker object.
dragbooleanfalseWhether the marker can be dragged on the map.
iconIconValueThe icon value for the marker. If both icon and svgIcon are set, icon is used.
labelstring or MarkerLabelThe label for the marker.
latnumber or stringThe latitude for the marker. This is an alternate option to position and latitude. You should set this if you are setting longitude or lng.
latitudenumber or stringThe latitude for the marker. This is an alternate option to position and lat. You should set this if you are setting longitude or lng.
lngnumber or stringThe longitude for the marker. This is an alternate option to position and longitude. You should set this if you are setting latitude or lat.
longitudenumber or stringThe longitude for the marker. This is an alternate option to position and lng. You should set this if you are setting latitude or lat.
mapMapThe map that the marker should show on.
positionLatLngValueThe Marker position
svgIconstring or SvgSymbolOptions or SvgSymbolAn SVG icon for the marker. A string is the full SVG markup (the whole <svg> element, not just the path code). An object is passed to G.svgSymbol(). This is ignored if icon is set. See SVG icons.
titlestringThe title for the marker. If a custom tooltip is not used, this will show as a default tooltip on the marker.
tooltipTooltipValueThe tooltip for the marker. This will show when hovering over the marker. If title is also set, it's used as the tooltip content when the tooltip options don't set content, and the default title tooltip isn't shown.

SVG icons​

The svgIcon option lets you use SVG for the marker icon. It can be set in two ways.

Pass the full SVG markup as a string.

The string must be the complete <svg> element, not only the path code. The markup is base64 encoded into a data:image/svg+xml;base64,... URL, and that URL is used as the marker icon image. Because it's shown as an image, include the xmlns attribute and set a width and height.

const marker = G.marker({
position: [48.9, 2.4],
map: map,
svgIcon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<circle cx="12" cy="12" r="10" fill="#5284ed" stroke="#ffffff" stroke-width="2" />
</svg>`,
});

The markup is encoded with the browser's btoa() function, so it can only contain Latin-1 characters.

Pass an SvgSymbol options object or an SvgSymbol object.

The value is passed to G.svgSymbol() and the resulting SvgSymbol is used as the icon. With this form you only set the SVG path value, not the full SVG markup. See the SvgSymbol options.

const marker = G.marker({
position: [48.9, 2.4],
map: map,
svgIcon: {
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
anchor: [6, 6],
fillColor: '#5284ed',
fillOpacity: 1,
strokeColor: '#ffffff',
strokeWeight: 2,
},
});

To change the icon after the marker is created, use setIcon().

Events​

The Google Map marker events can be used, along with the ready event that is specific to this library.

You can use the plain text name for the event, or you can use the event constant. Most events also have a helper method to add a listener.

EventConstantHelper methodDescription
animation_changedANIMATION_CHANGEDonAnimationChangedThe marker's animation changes.
clickCLICKonClickThe marker icon is clicked.
clickable_changedCLICKABLE_CHANGEDonClickableChangedThe marker's clickable property changes.
contextmenuCONTEXT_MENUonContextMenuThe DOM contextmenu event is fired on the marker.
cursor_changedCURSOR_CHANGEDonCursorChangedThe marker's cursor property changes.
dblclickDBLCLICKonDblClickThe marker is double clicked.
dragDRAGonDragThe user drags the marker.
dragendDRAG_ENDonDragEndThe user stops dragging the marker.
draggable_changedDRAGGABLE_CHANGEDonDraggableChangedThe marker's draggable property changes.
dragstartDRAG_STARTonDragStartThe user starts dragging the marker.
flat_changedFLAT_CHANGEDonFlatChangedThe marker's flat property changes.
icon_changedICON_CHANGEDonIconChangedThe marker's icon property changes.
mousedownMOUSE_DOWNonMouseDownThe user's mouse is pressed down on the marker.
mouseoutMOUSE_OUTonMouseOutThe user's mouse leaves the marker icon.
mouseoverMOUSE_OVERonMouseOverThe user's mouse enters the marker icon.
mouseupMOUSE_UPonMouseUpThe mouseup event is fired on the marker.
position_changedPOSITION_CHANGEDonPositionChangedThe marker's position property changes.
readyREADYonReadyThe marker is loaded and ready for use. This event is specific to this library.
shape_changedSHAPE_CHANGEDonShapeChangedThe marker's shape property changes.
title_changedTITLE_CHANGEDonTitleChangedThe marker's title property changes.
visible_changedVISIBLE_CHANGEDonVisibleChangedThe marker's visible property changes.
zindex_changedZINDEX_CHANGEDonZIndexChangedThe marker's zIndex property changes.
marker.on('click', (e) => {
// Do something
});

// Or, use the event constant
marker.on(G.MarkerEvents.CLICK, (e) => {
// Do something
});

// Or, use the helper method
marker.onClick((e) => {
// Do something
});

ready​

marker.on('ready', () => {
// Do something - the marker is ready
});

// You can use the event constant
marker.on(G.MarkerEvents.READY, () => {
// Do something
});

// Or, use the onReady method
marker.onReady(() => {
// Do something
});

Properties​

  • Properties inherited from Layer.
PropertyTypeDescription
anchorPointPointThe offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor. It can be set with a PointValue.
cursorstringThe cursor type to show on hover.
dataCustomDataAn object that holds custom data to attach to the marker object.
dragbooleanWhether the marker can be dragged on the map. Setting it calls enableDrag() or disableDrag().
iconIcon, SvgSymbol, or stringThe icon value for the marker. A string is an image URL. If the svgIcon option was set with SVG markup, this is the data:image/svg+xml URL. Setting it calls setIcon().
labelstring, number, or MarkerLabelThe label for the marker.
mapMapThe map that the marker should show on. Set it to null to remove the marker from the map.
positionLatLngThe Marker position. If the marker was dragged, this is its current position. It can be set with a LatLngValue.
titlestringThe title for the marker. If a custom tooltip is not used, this will show as a default tooltip on the marker.

Methods​

  • Methods inherited from Layer.
  • Methods inherited from Evented.
  • Methods inherited from Base

disableDrag​

disableDrag(): Promise<Marker>

Disable the ability to drag the marker on the map

marker.disableDrag();

display​

display(map: Map): Marker

Add the marker to the map and display it. This is an alias to show().

ParameterTypeRequiredDescription
mapMapYesThe map object
marker.display(map);

enableDrag​

enableDrag(): Promise<Marker>

Enable the ability to drag the marker on the map

marker.enableDrag();

getData​

getData(key?: string): any

Gets either all the custom data attached to the marker object or the value for a specific data key from the custom data object.

If the key is specified but the value doesn't exist in the custom data object, then null is returned.

ParameterTypeRequiredDescription
keystringNoThe object key to get a specific piece of data from the custom data obect. If this is not set then the entire custom data object is returned.

Get the entire data object.

const customData = marker.getData();

Get a specific value from the custom data object.

const customValue = marker.getData('dataKey');

getPosition​

getPosition(): LatLng

Get the marker position

const position = marker.getPosition();

hide​

hide(): Marker

Remove the marker from the map to hide it.

marker.hide();

isDraggable​

isDraggable(): boolean

Returns whether the marker is draggable.

if (marker.isDraggable()) {
// Do something
}

onAnimationChanged​

onAnimationChanged(callback: EventCallback): void

Callback for when the marker's animation changes.

This is a convenience function for marker.on(G.MarkerEvents.ANIMATION_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onAnimationChanged(() => {
// Do something
})

onClick​

onClick(callback: EventCallback): void

Callback for when the marker icon is clicked.

This is a convenience function for marker.on(G.MarkerEvents.CLICK, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onClick(() => {
// Do something
})

onClickableChanged​

onClickableChanged(callback: EventCallback): void

Callback for when the marker clickable property changes.

This is a convenience function for marker.on(G.MarkerEvents.CLICKABLE_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onClickableChanged(() => {
// Do something
})

onContextMenu​

onContextMenu(callback: EventCallback): void

Callback for when the DOM contextmenu is fired on the marker.

This is a convenience function for marker.on(G.MarkerEvents.CONTEXT_MENU, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onContextMenu(() => {
// Do something
})

onCursorChanged​

onCursorChanged(callback: EventCallback): void

Callback for when the marker cursor property changes.

This is a convenience function for marker.on(G.MarkerEvents.CURSOR_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onCursorChanged(() => {
// Do something
})

onDblClick​

onDblClick(callback: EventCallback): void

Callback for when the marker is double clicked.

This is a convenience function for marker.on(G.MarkerEvents.DBLCLICK, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onDblClick(() => {
// Do something
})

onDrag​

onDrag(callback: EventCallback): void

Callback for when the user drags the marker.

This is a convenience function for marker.on(G.MarkerEvents.DRAG, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onDrag(() => {
// Do something
})

The callback function has one parameter and that's the event object. It contains the following values:

PropertyTypeDescription
domEventGoogle Maps domEventThe corresponding navigation DOM event.
latLngLatLngThe position of the marker
typestringThe event type. In this case, drag.

See onDragEnd for more information about getting the marker location when this event is called.

onDragEnd​

onDragEnd(callback: EventCallback): void

Callback for when the user stops dragging the marker.

This is a convenience function for marker.on(G.MarkerEvents.DRAG_END, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onDragEnd(() => {
// Do something
})

The callback function has one parameter and that's the event object. It contains the following values:

PropertyTypeDescription
domEventGoogle Maps domEventThe corresponding navigation DOM event.
latLngLatLngThe position of the marker
typestringThe event type. In this case, dragend.

Typically you want to get the location of the marker. There are two ways to do this.

Option 1: Get it from the event object.

marker.onDragEnd((e) => {
const lat = e.latLng.lat;
const lng = e.latLng.lng;
})

Option 2: Get it from the marker object.

marker.onDragEnd(() => {
const position = marker.getPosition();
const lat = position.lat;
const lng = position.lng;
})

Or, get it from the marker position property, which is a LatLng object.

marker.onDragEnd(() => {
const lat = marker.position.lat;
const lng = marker.position.lng;
})

onDraggableChanged​

onDraggableChanged(callback: EventCallback): void

Callback for when the marker draggable property changes.

This is a convenience function for marker.on(G.MarkerEvents.DRAGGABLE_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onDraggableChanged(() => {
// Do something
})

onDragStart​

onDragStart(callback: EventCallback): void

Callback for when the user starts dragging the marker.

This is a convenience function for marker.on(G.MarkerEvents.DRAG_START, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onDragStart(() => {
// Do something
})

The callback function has one parameter and that's the event object. It contains the following values:

PropertyTypeDescription
domEventGoogle Maps domEventThe corresponding navigation DOM event.
latLngLatLngThe position of the marker
typestringThe event type. In this case, dragstart.

See onDragEnd for more information about getting the marker location when this event is called.

onFlatChanged​

onFlatChanged(callback: EventCallback): void

Callback for when the marker flat property changes.

This is a convenience function for marker.on(G.MarkerEvents.FLAT_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onFlatChanged(() => {
// Do something
})

onIconChanged​

onIconChanged(callback: EventCallback): void

Callback for when the marker icon property changes.

This is a convenience function for marker.on(G.MarkerEvents.ICON_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onIconChanged(() => {
// Do something
})

onMouseDown​

onMouseDown(callback: EventCallback): void

Callback for when the when the user's mouse is pressed down on the marker.

This is a convenience function for marker.on(G.MarkerEvents.MOUSE_DOWN, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onMouseDown(() => {
// Do something
})

onMouseOut​

onMouseOut(callback: EventCallback): void

Callback for when the when the user's mouse exits the marker icon.

This is a convenience function for marker.on(G.MarkerEvents.MOUSE_OUT, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onMouseOut(() => {
// Do something
})

onMouseOver​

onMouseOver(callback: EventCallback): void

Callback for when the when the user's mouse enters the marker icon.

This is a convenience function for marker.on(G.MarkerEvents.MOUSE_OVER, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onMouseOver(() => {
// Do something
})

onMouseUp​

onMouseUp(callback: EventCallback): void

Callback for the mouseup event on the marker.

This is a convenience function for marker.on(G.MarkerEvents.MOUSE_UP, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onMouseUp(() => {
// Do something
})

onPositionChanged​

onPositionChanged(callback: EventCallback): void

Callback for when the marker's position property changes.

This is a convenience function for marker.on(G.MarkerEvents.POSITION_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onPositionChanged(() => {
// Do something
})

onReady​

onReady(callback: EventCallback): void

Callback for when the marker is loaded and ready for use.

This is a convenience function for marker.on(G.MarkerEvents.READY, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onReady(() => {
// Do something
})

onShapeChanged​

onShapeChanged(callback: EventCallback): void

Callback for when the marker's shape property changes.

This is a convenience function for marker.on(G.MarkerEvents.SHAPE_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onShapeChanged(() => {
// Do something
})

onTitleChanged​

onTitleChanged(callback: EventCallback): void

Callback for when the marker's title property changes.

This is a convenience function for marker.on(G.MarkerEvents.TITLE_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onTitleChanged(() => {
// Do something
})

onVisibleChanged​

onVisibleChanged(callback: EventCallback): void

Callback for when the marker's visible property changes.

This is a convenience function for marker.on(G.MarkerEvents.VISIBLE_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onVisibleChanged(() => {
// Do something
})

onZIndexChanged​

onZIndexChanged(callback: EventCallback): void

Callback for when the marker's zindex property changes.

This is a convenience function for marker.on(G.MarkerEvents.ZINDEX_CHANGED, callback).

ParameterTypeRequiredDescription
callbackFunctionYesThe callback function that will be called when the event is dispatched.
marker.onZIndexChanged(() => {
// Do something
})

setAnchorPoint​

setAnchorPoint(value: PointValue): Promise<Marker>

Set the anchor point for the marker.

ParameterTypeRequiredDescription
valuePointValueYesThe offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor.
marker.setAnchorPoint([3, 10]);

setAnchorPointSync​

setAnchorPointSync(value: PointValue): Marker

Set the anchor point for the marker syncronously.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setAnchorPoint() instead or pass the anchorPoint option to the constructor or setOptions().

ParameterTypeRequiredDescription
valuePointValueYesThe offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor.
marker.setAnchorPointSync([3, 10]);

setCursor​

setCursor(value: string): Promise<Marker>

Set the mouse cursor type to show when hovering over the marker.

ParameterTypeRequiredDescription
valuestringYesThe mouse cursor type.
marker.setCursor('help');

setCursorSync​

setCursorSync(value: string): Marker

Syncronously set the mouse cursor type to show when hovering over the marker.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setCursor() instead or pass the cursor option to the constructor or setOptions().

ParameterTypeRequiredDescription
valuestringYesThe mouse cursor type.
marker.setCursorSync('help');

setIcon​

setIcon(value: Icon | SvgSymbol | string): Promise<Marker>

Set the icon value for the marker.

ParameterTypeRequiredDescription
valueIcon, SvgSymbol, or stringYesThe icon for the marker. Pass null to clear the value.

If value is a string then it's used as the image URL for the icon. It's not passed through G.icon(), and SVG markup is not converted like it is with the svgIcon option.

Unlike the icon and svgIcon options, this method does not accept an options object. Use G.icon() or G.svgSymbol() to create the object first.

Set the icon using an Icon object:

const icon = G.icon({
url: 'https://mywebsite.com/images/marker.png',
size: [20, 32]
});
marker.setIcon(icon);

Set the icon using an SvgSymbol object:

const icon = G.svgSymbol({
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});
marker.setIcon(icon);

Set the icon value using a URL string:

marker.setIcon('https://mywebsite.com/images/marker.png');

Set the icon to SVG markup by converting it to a data URL yourself. This is what the svgIcon option does with a string.

const svg = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><circle cx="12" cy="12" r="10" fill="#5284ed" /></svg>';
marker.setIcon(`data:image/svg+xml;base64,${btoa(svg)}`);

setIconSync​

setIconSync(value: Icon | SvgSymbol | string): Marker

Syncronously set the icon value for the marker.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setIcon() instead or pass the icon option to the constructor or setOptions().

ParameterTypeRequiredDescription
valueIcon, SvgSymbol, or stringYesThe icon for the marker. Pass null to clear the value.

The value is handled the same way as setIcon(). If value is a string then it's used as the image URL for the icon.

Set the icon using an Icon object:

const icon = G.icon({
url: 'https://mywebsite.com/images/marker.png',
size: [20, 32]
});
marker.setIconSync(icon);

Set the icon using an SvgSymbol object:

const icon = G.svgSymbol({
path: 'M0,6a6,6 0 1,0 12,0a6,6 0 1,0 -12,0',
fillColor: '#5284ed',
fillOpacity: 1,
scale: 1,
strokeColor: '#5284ed',
strokeOpacity: 0.5,
strokeWeight: 4,
});
marker.setIconSync(icon);

Set the icon value using a URL string:

marker.setIconSync('https://mywebsite.com/images/marker.png');

setLabel​

setLabel(value: string | number | MarkerLabel): Promise<Marker>

Set the label value for the marker.

ParameterTypeRequiredDescription
valuestring, number, or MarkerLabelYesThe label for the marker.

Set the label as a string:

marker.setLabel('Marker label');

Set the label as a number:

marker.setLabel(15);

Set the label as a MarkerLabel object:

marker.setLabel({
className: 'myLabelClass',
fontSize: '18px',
text: 'Label text here'
});

setLabelSync​

setLabelSync(value: string | number | MarkerLabel): Marker

Syncronously set the label value for the marker.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setLabel() instead or pass the label option to the constructor or setOptions().

ParameterTypeRequiredDescription
valuestring, number, or MarkerLabelYesThe label for the marker.

Set the label as a string:

marker.setLabelSync('Marker label');

Set the label as a number:

marker.setLabelSync(15);

Set the label as a MarkerLabel object:

marker.setLabelSync({
className: 'myLabelClass',
fontSize: '18px',
text: 'Label text here'
});

setMap​

setMap(map: Map | null): Promise<Marker>

Add the marker to the map and display it. This is an alias to show(). Pass null to remove the marker from the map.

If the map hasn't been rendered yet, for example because its element is hidden, the marker is added once the map is ready.

ParameterTypeRequiredDescription
mapMap or nullYesThe map object, or null to remove the marker from the map.
marker.setMap(map);

// Remove the marker from the map
marker.setMap(null);

setMapSync​

setMapSync(map: Map | null): Marker

Syncronously add the marker to the map and display it. Pass null to remove the marker from the map.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setMap() instead or pass the map option to the constructor or setOptions().

ParameterTypeRequiredDescription
mapMap or nullYesThe map object, or null to remove the marker from the map.
marker.setMapSync(map);

setOptions​

setOptions(options: MarkerOptions): Marker

Set the options for the marker.

ParameterTypeRequiredDescription
optionsMarkerOptionsYesThe marker options.
marker.setOptions({position: [38.6270, 90.1994]});

setPosition​

setPosition(value: LatLngValue): Promise<Marker>

Set the position of the marker.

ParameterTypeRequiredDescription
valueLatLngValueYesThe marker position.
marker.setPosition([49.864716, 2.6522]);

setPositionSync​

setPositionSync(value: LatLngValue): Marker

Syncronously set the position of the marker.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setPosition() instead or pass the position option to the constructor or setOptions().

ParameterTypeRequiredDescription
valueLatLngValueYesThe marker position.
marker.setPositionSync([49.864716, 2.6522]);

setTitle​

setTitle(value: string): Promise<Marker>

Set the title for the marker.

ParameterTypeRequiredDescription
valuestringYesThe marker title.
marker.setTitle('Marker title');

setTitleSync​

setTitleSync(value: string): Marker

Syncronously set the title of the marker.

Only use this if you know that the Google Maps library is already loaded and you have to set up the marker syncronously. If you don't have to set up the marker syncronously, then use setTitle() instead or pass the title option to the constructor or setOptions().

ParameterTypeRequiredDescription
valuestringYesThe marker title.
marker.setTitleSync('Marker title');

show​

show(map: Map): Promise<Marker>

Add the marker to the map and display it. This is an alias to setMap.

ParameterTypeRequiredDescription
mapMapYesThe map object
marker.show(map);

toGoogle​

toGoogle(): Promise<google.maps.Marker>

Returns the Google Maps Marker object. It will be a promise value.

marker.toGoogle().then((googleMarker) => {
// Do something with the Google marker object
});

toGoogleSync​

toGoogleSync(): google.maps.Marker

Syncronously returns the Google Maps Marker object.

This is different from toGoogle() because it will throw an error if the Google Maps library is not available, whereas toGoogle() will wait for the Google Maps library to load. (This is the same with all of the Sync versions of the marker methods.)

Only use this when you have to get the Google Maps object synchronously and you know that the Google Maps library is already loaded. If you don't have to get the Google Maps object synchronously, then use toGoogle() instead.

const googleMarker = marker.toGoogleSync();