public final class

Marker

extends Object
java.lang.Object
   ↳ com.google.android.gms.maps.model.Marker

Class Overview

An icon placed at a particular point on the map's surface. A marker icon is drawn oriented against the device's screen rather than the map's surface; i.e., it will not necessarily change orientation due to map rotations, tilting, or zooming.

A marker has the following properties:

Anchor
The point on the image that will be placed at the LatLng position of the marker. This defaults to 50% from the left of the image and at the bottom of the image.
Position
The LatLng value for the marker's position on the map. You can change this value at any time if you want to move the marker.
Title
A text string that's displayed in an info window when the user taps the marker. You can change this value at any time.
Snippet
Additional text that's displayed below the title. You can change this value at any time.
Icon
A bitmap that's displayed for the marker. If the icon is left unset, a default icon is displayed. You can specify an alternative coloring of the default icon using defaultMarker(float). You can't change the icon once you've created the marker.
Drag Status
If you want to allow the user to drag the marker, set this property to true. You can change this value at any time. The default is false.
Visibility
By default, the marker is visible. To make the marker invisible, set this property to false. You can change this value at any time.

Example

 GoogleMap map = ... // get a map.
 // Add a marker at San Francisco.
 Marker marker = map.addMarker(new MarkerOptions()
     .position(new LatLng(37.7750, 122.4183))
     .title("San Francisco")
     .snippet("Population: 776733"));

Developer Guide

For more information, read the Markers developer guide.

Summary

Public Methods
boolean equals(Object other)
String getId()
Gets this marker's id.
LatLng getPosition()
Returns the position of the marker.
String getSnippet()
Gets the snippet of the marker.
String getTitle()
Gets the title of the marker.
int hashCode()
void hideInfoWindow()
Hides the info window if it is shown from this marker.
boolean isDraggable()
Gets the draggability of the marker.
boolean isInfoWindowShown()
Returns whether the info window is currently shown above this marker.
boolean isVisible()
void remove()
Removes this marker from the map.
void setAnchor(float anchorU, float anchorV)
Sets the anchor point for the marker.
void setDraggable(boolean draggable)
Sets the draggability of the marker.
void setIcon(BitmapDescriptor icon)
Sets the icon for the marker.
void setPosition(LatLng latlng)
Sets the position of the marker.
void setSnippet(String snippet)
Sets the snippet of the marker.
void setTitle(String title)
Sets the title of the marker.
void setVisible(boolean visible)
Sets the visibility of this marker.
void showInfoWindow()
Shows the info window of this marker on the map, if this marker isVisible().
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public boolean equals (Object other)

public String getId ()

Gets this marker's id.

When a map is restored from a Bundle, markers that were on that map are also restored. However, those markers will then be represented by different Marker objects. A marker's id can be used to retrieve the new instance of a Marker object after such restoration.

Returns
  • this marker's id.

public LatLng getPosition ()

Returns the position of the marker.

Returns
  • A LatLng object specifying the marker's current position.

public String getSnippet ()

Gets the snippet of the marker.

Returns
  • A string containing the marker's snippet.

public String getTitle ()

Gets the title of the marker.

Returns
  • A string containing the marker's title.

public int hashCode ()

public void hideInfoWindow ()

Hides the info window if it is shown from this marker.

This method has no effect if this marker is not visible.

public boolean isDraggable ()

Gets the draggability of the marker. When a marker is draggable, it can be moved by the user by long pressing on the marker.

Returns
  • true if the marker is draggable; otherwise, returns false.

public boolean isInfoWindowShown ()

Returns whether the info window is currently shown above this marker. This does not consider whether or not the info window is actually visible on screen.

public boolean isVisible ()

public void remove ()

Removes this marker from the map. After a marker has been removed, the behavior of all its methods is undefined.

public void setAnchor (float anchorU, float anchorV)

Sets the anchor point for the marker.

The anchor specifies the point in the icon image that is anchored to the marker's position on the Earth's surface.

The anchor point is specified in the continuous space [0.0, 1.0] x [0.0, 1.0], where (0, 0) is the top-left corner of the image, and (1, 1) is the bottom-right corner. The anchoring point in a W x H image is the nearest discrete grid point in a (W + 1) x (H + 1) grid, obtained by scaling the then rounding. For example, in a 4 x 2 image, the anchor point (0.7, 0.6) resolves to the grid point at (3, 1).

 *-----+-----+-----+-----*
 |     |     |     |     |
 |     |     |     |     |
 +-----+-----+-----+-----+
 |     |     |   X |     |   (U, V) = (0.7, 0.6)
 |     |     |     |     |
 *-----+-----+-----+-----*

 *-----+-----+-----+-----*
 |     |     |     |     |
 |     |     |     |     |
 +-----+-----+-----X-----+   (X, Y) = (3, 1)
 |     |     |     |     |
 |     |     |     |     |
 *-----+-----+-----+-----*
 

Parameters
anchorU u-coordinate of the anchor, as a ratio of the image width (in the range [0, 1])
anchorV v-coordinate of the anchor, as a ratio of the image height (in the range [0, 1])

public void setDraggable (boolean draggable)

Sets the draggability of the marker. When a marker is draggable, it can be moved by the user by long pressing on the marker.

public void setIcon (BitmapDescriptor icon)

Sets the icon for the marker.

Parameters
icon if null, the default marker is used.

public void setPosition (LatLng latlng)

Sets the position of the marker.

public void setSnippet (String snippet)

Sets the snippet of the marker.

public void setTitle (String title)

Sets the title of the marker.

public void setVisible (boolean visible)

Sets the visibility of this marker. If set to false and an info window is currently showing for this marker, this will hide the info window.

public void showInfoWindow ()

Shows the info window of this marker on the map, if this marker isVisible().

Throws
IllegalArgumentException if marker is not on this map