Marker class
google.maps.Marker
class
This class extends
MVCObject.
Access by calling const {Marker} = await google.maps.importLibrary("marker"). 
See Libraries in the Maps JavaScript API.
| Constructor | |
|---|---|
| Marker | Marker([opts])Parameters:   
 Creates a marker with the options specified. If a map is specified, the marker is added to the map upon construction. Note that the position must be set for the marker to display. | 
| Constants | |
|---|---|
| MAX_ZINDEX | The maximum default z-index that the API will assign to a marker. You may set a higher z-index to bring a marker to the front. | 
| Methods | |
|---|---|
| getAnimation | getAnimation()Parameters:  None Return Value:   Animation|null|undefinedGet the currently running animation. | 
| getClickable | getClickable()Parameters:  None Return Value:   booleanTrue if the Marker is clickable.Get the clickable status of the  Marker. | 
| getCursor | getCursor()Parameters:  None Return Value:   string|null|undefinedGet the mouse cursor type shown on hover. | 
| getDraggable | getDraggable()Parameters:  None Return Value:   booleanTrue if the Marker is draggable.Get the draggable status of the  Marker. | 
| getIcon | getIcon()Parameters:  None Get the icon of the  Marker. SeeMarkerOptions.icon. | 
| getLabel | getLabel()Parameters:  None Return Value:   MarkerLabel|string|null|undefinedGet the label of the  Marker. SeeMarkerOptions.label. | 
| getMap | getMap()Parameters:  None Return Value:   Map|StreetViewPanorama|nullGet the map or panaroama the  Markeris rendered on. | 
| getOpacity | getOpacity()Parameters:  None Return Value:   number|null|undefinedA number between 0.0 and 1.0.Get the opacity of the  Marker. | 
| getPosition | getPosition()Parameters:  None Return Value:   LatLng|null|undefinedGet the position of the  Marker. | 
| getShape | getShape()Parameters:  None Return Value:   MarkerShape|null|undefined | 
| getTitle | getTitle()Parameters:  None Return Value:   string|null|undefinedGet the title of the  Markertooltip. SeeMarkerOptions.title. | 
| getVisible | getVisible()Parameters:  None Return Value:   booleanTrue if the Marker is visible.Get the visibility of the  Marker. | 
| getZIndex | getZIndex()Parameters:  None Return Value:   number|null|undefinedzIndex of the Marker.Get the zIndex of the  Marker. SeeMarkerOptions.zIndex. | 
| setAnimation | setAnimation([animation])Parameters:   
 Return Value:  None Start an animation. Any ongoing animation will be cancelled. Currently supported animations are:  Animation.BOUNCE,Animation.DROP. Passing innullwill cause any animation to stop. | 
| setClickable | setClickable(flag)Parameters:   
 Return Value:  None Set if the  Markeris clickable. | 
| setCursor | setCursor([cursor])Parameters:   
 Return Value:  None Set the mouse cursor type shown on hover. | 
| setDraggable | setDraggable(flag)Parameters:   
 Return Value:  None Set if the  Markeris draggable. | 
| setIcon | setIcon([icon])Return Value:  None Set the icon for the  Marker. SeeMarkerOptions.icon. | 
| setLabel | setLabel([label])Parameters:   
 Return Value:  None Set the label for the  Marker. SeeMarkerOptions.label. | 
| setMap | setMap(map)Parameters:   
 Return Value:  None Renders the  Markeron the specified map or panorama. If map is set tonull, the marker will be removed. | 
| setOpacity | setOpacity([opacity])Parameters:   
 Return Value:  None Set the opacity of the  Marker. | 
| setOptions | setOptions(options)Parameters:   
 Return Value:  None Set the options for the  Marker. | 
| setPosition | setPosition([latlng])Parameters:   
 Return Value:  None Set the postition for the  Marker. | 
| setShape | setShape([shape])Parameters:   
 Return Value:  None | 
| setTitle | setTitle([title])Parameters:   
 Return Value:  None Set the title of the  Markertooltip. SeeMarkerOptions.title. | 
| setVisible | setVisible(visible)Parameters:   
 Return Value:  None Set if the  Markeris visible. | 
| setZIndex | setZIndex([zIndex])Parameters:   
 Return Value:  None Set the zIndex of the  Marker. SeeMarkerOptions.zIndex. | 
| Inherited: addListener,bindTo,get,notify,set,setValues,unbind,unbindAll | |
| Events | |
|---|---|
| animation_changed | function()Arguments:  None This event is fired when the  Markeranimation property changes. | 
| click | function(event)Arguments:   
 This event is fired when the  Markericon was clicked. | 
| clickable_changed | function()Arguments:  None This event is fired when the  Markerclickable property changes. | 
| contextmenu | function(event)Arguments:   
 This event is fired when the DOM contextmenu event is fired on the  Marker | 
| cursor_changed | function()Arguments:  None This event is fired when the  Markercursor property changes. | 
| dblclick | function(event)Arguments:   
 This event is fired when the  Markericon was double clicked. | 
| drag | function(event)Arguments:   
 This event is repeatedly fired while the user drags the  Marker. | 
| dragend | function(event)Arguments:   
 This event is fired when the user stops dragging the  Marker. | 
| draggable_changed | function()Arguments:  None This event is fired when the  Markerdraggable property changes. | 
| dragstart | function(event)Arguments:   
 This event is fired when the user starts dragging the  Marker. | 
| flat_changed | function()Arguments:  None This event is fired when the  Markerflat property changes. | 
| icon_changed | function()Arguments:  None This event is fired when the  Markericon property changes. | 
| mousedown | function(event)Arguments:   
 This event is fired for a mousedown on the  Marker. | 
| mouseout | function(event)Arguments:   
 This event is fired when the mouse leaves the area of the  Markericon. | 
| mouseover | function(event)Arguments:   
 This event is fired when the mouse enters the area of the  Markericon. | 
| mouseup | function(event)Arguments:   
 This event is fired for a mouseup on the  Marker. | 
| position_changed | function()Arguments:  None This event is fired when the  Markerposition property changes. | 
| shape_changed | function()Arguments:  None This event is fired when the  Markershape property changes. | 
| title_changed | function()Arguments:  None This event is fired when the  Markertitle property changes. | 
| visible_changed | function()Arguments:  None This event is fired when the  Markervisible property changes. | 
| zindex_changed | function()Arguments:  None This event is fired when the  MarkerzIndex property changes. | 
|  | function(event)Arguments:   
 This event is fired for a rightclick on the  Marker. | 
MarkerOptions interface
google.maps.MarkerOptions
interface
MarkerOptions object used to define the properties that can be set on a Marker.
| Properties | |
|---|---|
| anchorPoint optional | Type:   Point optionalThe offset from the marker's position to the tip of an InfoWindow that has been opened with the marker as anchor. | 
| animation optional | Type:   Animation optionalDefault:  nullWhich animation to play when marker is added to a map. | 
| clickable optional | Type:   boolean optionalDefault:  trueIf  true, the marker receives mouse and touch events. | 
|  | Type:   string|CollisionBehavior optionalDefault:  nullSet a collision behavior for markers on vector maps. | 
| crossOnDrag optional | Type:   boolean optionalDefault:  trueIf  false, disables cross that appears beneath the marker when dragging. | 
| cursor optional | Type:   string optionalDefault:  pointerMouse cursor type to show on hover. | 
| draggable optional | Type:   boolean optionalDefault:  falseIf  true, the marker can be dragged. Note: Setting this totruewill make the marker clickable even ifclickableis set tofalse. | 
| icon optional | Icon for the foreground. If a string is provided, it is treated as though it were an  Iconwith the string asurl. | 
| label optional | Type:   string|MarkerLabel optionalDefault:  nullAdds a label to the marker. A marker label is a letter or number that appears inside a marker. The label can either be a string, or a  MarkerLabelobject. If provided andMarkerOptions.titleis not provided, an accessibility text (e.g. for use with screen readers) will be added to the marker with the provided label's text. Please note that thelabelis currently only used for accessibility text for non-optimized markers. | 
| map optional | Type:   Map|StreetViewPanorama optionalMap on which to display Marker. The map is required to display the marker and can be provided with  Marker.setMapif not provided at marker construction. | 
| opacity optional | Type:   number optionalDefault: 1.0 A number between 0.0, transparent, and 1.0, opaque. | 
| optimized optional | Type:   boolean optionalOptimization enhances performance by rendering many markers as a single static element. This is useful in cases where a large number of markers is required. Read more about marker optimization. Note: This optimization has no effect for markers on vector maps. | 
| position optional | Type:   LatLng|LatLngLiteral optionalSets the marker position. A marker may be constructed but not displayed until its position is provided - for example, by a user's actions or choices. A marker position can be provided with  Marker.setPositionif not provided at marker construction. | 
| shape optional | Type:   MarkerShape optionalImage map region definition used for drag/click. | 
| title optional | Type:   string optionalDefault:  undefinedRollover text. If provided, an accessibility text (e.g. for use with screen readers) will be added to the marker with the provided value. Please note that the  titleis currently only used for accessibility text for non-optimized markers. | 
| visible optional | Type:   boolean optionalDefault:  trueIf  true, the marker is visible. | 
| zIndex optional | Type:   number optionalAll markers are displayed on the map in order of their zIndex, with higher values displaying in front of markers with lower values. By default, markers are displayed according to their vertical position on screen, with lower markers appearing in front of markers further up the screen. | 
CollisionBehavior constants
google.maps.CollisionBehavior
constants
Access by calling const {CollisionBehavior} = await google.maps.importLibrary("marker"). 
See Libraries in the Maps JavaScript API.
| Constants | |
|---|---|
| OPTIONAL_AND_HIDES_LOWER_PRIORITY | Display the marker only if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher zIndex is shown. If they have the same zIndex, the one with the lower vertical screen position is shown. | 
| REQUIRED | Always display the marker regardless of collision. This is the default behavior. | 
| REQUIRED_AND_HIDES_OPTIONAL | Always display the marker regardless of collision, and hide any OPTIONAL_AND_HIDES_LOWER_PRIORITY markers or labels that would overlap with the marker. | 
Icon interface
google.maps.Icon
interface
A structure representing a Marker icon image.
| Properties | |
|---|---|
| url | Type:   stringThe URL of the image or sprite sheet. | 
| anchor optional | Type:   Point optionalThe position at which to anchor an image in correspondence to the location of the marker on the map. By default, the anchor is located along the center point of the bottom of the image. | 
| labelOrigin optional | Type:   Point optionalThe origin of the label relative to the top-left corner of the icon image, if a label is supplied by the marker. By default, the origin is located in the center point of the image. | 
| origin optional | Type:   Point optionalThe position of the image within a sprite, if any. By default, the origin is located at the top left corner of the image  (0, 0). | 
| scaledSize optional | Type:   Size optionalThe size of the entire image after scaling, if any. Use this property to stretch/shrink an image or a sprite. | 
| size optional | Type:   Size optionalThe display size of the sprite or image. When using sprites, you must specify the sprite size. If the size is not provided, it will be set when the image loads. | 
MarkerLabel interface
google.maps.MarkerLabel
interface
These options specify the appearance of a marker label. A marker label is a string (often a single character) which will appear inside the marker. If you are using it with a custom marker, you can reposition it with the labelOrigin property in the Icon class.
| Properties | |
|---|---|
| text | Type:   stringThe text to be displayed in the label. | 
| className optional | Type:   string optionalDefault:  ''(empty string)The className property of the label's element (equivalent to the element's class attribute). Multiple space-separated CSS classes can be added. The font color, size, weight, and family can only be set via the other properties of  MarkerLabel. CSS classes should not be used to change the position nor orientation of the label (e.g. using translations and rotations) if also using marker collision management. | 
| color optional | Type:   string optionalDefault:  'black'The color of the label text. | 
| fontFamily optional | Type:   string optionalThe font family of the label text (equivalent to the CSS font-family property). | 
| fontSize optional | Type:   string optionalDefault:  '14px'The font size of the label text (equivalent to the CSS font-size property). | 
| fontWeight optional | Type:   string optionalThe font weight of the label text (equivalent to the CSS font-weight property). | 
MarkerShape interface
google.maps.MarkerShape
interface
This object defines the clickable region of a marker image. The shape consists of two properties — type and coord — which define the non-transparent region of an image.
| Properties | |
|---|---|
| type | Type:   stringDescribes the shape's type and can be  circle,polyorrect. | 
| coords optional | Type:   Array<number> optionalThe format of this attribute depends on the value of the  typeand follows the w3 AREAcoordsspecification found at  http://www.w3.org/TR/REC-html40/struct/objects.html#adef-coords.The coordsattribute is an array of integers that specify the pixel position of the shape relative to the top-left corner of the target image. The coordinates depend on the value oftypeas follows:- circle: coords is[x1,y1,r]where x1,y2 are the coordinates of the center of the circle, and r is the radius of the circle.- poly: coords is[x1,y1,x2,y2...xn,yn]where each x,y pair contains the coordinates of one vertex of the polygon.- rect: coords is[x1,y1,x2,y2]where x1,y1 are the coordinates of the upper-left corner of the rectangle and x2,y2 are the coordinates of the lower-right coordinates of the rectangle. | 
Symbol interface
google.maps.Symbol
interface
Describes a symbol, which consists of a vector path with styling. A symbol can be used as the icon of a marker, or placed on a polyline.
| Properties | |
|---|---|
| path | Type:   SymbolPath|stringThe symbol's path, which is a built-in symbol path, or a custom path expressed using SVG path notation. Required. | 
| anchor optional | Type:   Point optionalDefault:  google.maps.Point(0,0)The position of the symbol relative to the marker or polyline. The coordinates of the symbol's path are translated left and up by the anchor's x and y coordinates respectively. The position is expressed in the same coordinate system as the symbol's path. | 
| fillColor optional | Type:   string optionalThe symbol's fill color. All CSS3 colors are supported except for extended named colors. For symbol markers, this defaults to 'black'. For symbols on polylines, this defaults to the stroke color of the corresponding polyline. | 
| fillOpacity optional | Type:   number optionalDefault:  0The symbol's fill opacity. | 
| labelOrigin optional | Type:   Point optionalDefault:  google.maps.Point(0,0)The origin of the label relative to the origin of the path, if label is supplied by the marker. The origin is expressed in the same coordinate system as the symbol's path. This property is unused for symbols on polylines. | 
| rotation optional | Type:   number optionalDefault:  0The angle by which to rotate the symbol, expressed clockwise in degrees. A symbol in an  IconSequencewherefixedRotationisfalseis rotated relative to the angle of the edge on which it lies. | 
| scale optional | Type:   number optionalThe amount by which the symbol is scaled in size. For symbol markers, this defaults to 1; after scaling, the symbol may be of any size. For symbols on a polyline, this defaults to the stroke weight of the polyline; after scaling, the symbol must lie inside a square 22 pixels in size centered at the symbol's anchor. | 
| strokeColor optional | Type:   string optionalThe symbol's stroke color. All CSS3 colors are supported except for extended named colors. For symbol markers, this defaults to 'black'. For symbols on a polyline, this defaults to the stroke color of the polyline. | 
| strokeOpacity optional | Type:   number optionalThe symbol's stroke opacity. For symbol markers, this defaults to 1. For symbols on a polyline, this defaults to the stroke opacity of the polyline. | 
| strokeWeight optional | Type:   number optionalDefault: The  Symbol.scaleof the symbol.The symbol's stroke weight. | 
SymbolPath constants
google.maps.SymbolPath
constants
Built-in symbol paths.
Access by calling const {SymbolPath} = await google.maps.importLibrary("core"). 
See Libraries in the Maps JavaScript API.
| Constants | |
|---|---|
| BACKWARD_CLOSED_ARROW | A backward-pointing closed arrow. | 
| BACKWARD_OPEN_ARROW | A backward-pointing open arrow. | 
| CIRCLE | A circle. | 
| FORWARD_CLOSED_ARROW | A forward-pointing closed arrow. | 
| FORWARD_OPEN_ARROW | A forward-pointing open arrow. | 
Animation constants
google.maps.Animation
constants
Animations that can be played on a marker. Use the Marker.setAnimation method on Marker or the MarkerOptions.animation option to play an animation.
Access by calling const {Animation} = await google.maps.importLibrary("marker"). 
See Libraries in the Maps JavaScript API.
| Constants | |
|---|---|
| BOUNCE | Marker bounces until animation is stopped by calling Marker.setAnimationwithnull. | 
| DROP | Marker drops from the top of the map to its final location. Animation will cease once the marker comes to rest and Marker.getAnimationwill returnnull. This type of animation is usually specified during creation of the marker. |