Markers indicate single locations on the map. You can customize your markers by changing the default color, or replacing the marker icon with a custom image. Info windows can provide additional context to a marker.
Markers identify locations on the map. The default marker uses a standard
icon, common to the Google Maps look and feel. It's possible to change the
icon's color, image or anchor point via the API. Markers are objects of type
Marker, and are added to the map with the
Markers are designed to be interactive. They receive
click events by
default, and are often used with event listeners to bring up info
windows. Setting a marker's
draggable property to
allows the user to change the position of the marker. Use a long press to
activate the ability to move the marker.
Video: Getting started with markers
This episode of Maps Live covers the basics of adding markers to your map using the Google Maps Android API v2.
Add a marker
The below example demonstrates how to add a marker to a map. The marker is
created at coordinates
0,0, and displays the string "Hello world" in an
info window when clicked.
private GoogleMap mMap; mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); mMap.addMarker(new MarkerOptions() .position(new LatLng(0, 0)) .title("Hello world"));
Make a marker draggable
You can reposition a marker once its been added to the map so long as its
draggable property is set to
true. Long press the marker to enable
dragging. When you take your finger off the screen, the marker will remain in
Markers are not draggable by default. You must explicitly set the marker to be draggable either with
MarkerOptions.draggable(boolean) prior to
adding it to the map, or
Marker.setDraggable(boolean) once it has been added
to the map. You can listen for drag events on the marker, as described in Marker drag events.
The below snippet adds a draggable marker at Perth, Australia.
static final LatLng PERTH = new LatLng(-31.90, 115.86); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(PERTH) .draggable(true));
Customize a marker
Markers may define a custom image to show in place of the default icon. Defining an icon involves setting a number of properties that affect the visual behavior of the marker.
Markers support customization through the following properties:
- Position (Required)
LatLngvalue for the marker's position on the map. This is the only required property for a
- The point on the image that will be placed at the LatLng position of the marker. This defaults to the middle of the bottom of the image.
- Sets the opacity of the marker. Defaults to 1.0.
- A string that's displayed in the info window when the user taps the marker.
- Additional text that's displayed below the title.
- A bitmap that's displayed in place of the default marker image.
- Set to
trueif you want to allow the user to move the marker. Defaults to
- Set to
falseto make the marker invisible. Defaults to
- Flat or Billboard orientation
- By default, markers are oriented against the screen, and will not rotate or tilt with the camera. Flat markers are oriented against the surface of the earth, and will rotate and tilt with the camera. Both types of markers do not change size based on zoom. Use GroundOverlays if you desire this effect.
- The orientation of the marker, specified in degrees clockwise. The default position changes if the marker is flat. The default position for a flat marker is north aligned. When the marker is not flat, the default position is pointing up and the rotation is such that the marker is always facing the camera.
The below snippet creates a simple marker, with the default icon.
static final LatLng MELBOURNE = new LatLng(-37.813, 144.962); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE));
Customize the marker color
It's possible to customize the color of the default marker image by passing a
BitmapDescriptor object to the icon() method. You can use a set of
predefined colors in the
object, or set a custom marker color with the
BitmapDescriptorFactory.defaultMarker(float hue) method. The hue is a value
between 0 and 360, representing points on a color wheel.
static final LatLng MELBOURNE = new LatLng(-37.813, 144.962); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
Customize the marker opacity
You can control the opacity of a marker with the MarkerOptions.alpha() method. Alpha should be specified as a float between 0.0 and 1.0, where 0 is fully transparent and 1 is fully opaque.
static final LatLng MELBOURNE = new LatLng(-37.813, 144.962); Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .alpha(0.7f));
Customize the marker image
You can replace the default marker image with a custom marker image, often
called an icon. Custom icons are always set as a
defined using one of four methods in the
- Creates a custom marker using an image in the assets directory.
fromBitmap (Bitmap image)
- Creates a custom marker from a Bitmap image.
fromFile (String path)
- Creates a custom icon from a file at the specified path.
fromResource (int resourceId)
- Creates a custom marker using an existing resource.
The below snippet creates a marker with a custom icon.
private static final LatLng MELBOURNE = new LatLng(-37.813, 144.962); private Marker melbourne = mMap.addMarker(new MarkerOptions() .position(MELBOURNE) .title("Melbourne") .snippet("Population: 4,137,400") .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));
Flatten a marker
Marker icons are normally drawn with respect to the screen; rotating, tilting or zooming the map will not change the orientation of the marker. You can set the orientation of a marker to be flat against the earth. Markers that are oriented in this way will rotate when the map is rotated, and change perspective when the map is tilted. Flat markers will retain their size when the map is zoomed in or out.
To change the orientation of the marker, set the marker's
flat property to
static final LatLng PERTH = new LatLng(-31.90, 115.86); Marker perth = mMap.addMarker(new MarkerOptions() .position(PERTH) .flat(true));
Rotate a marker
You can rotate a marker around its anchor point with the
setRotation() method. The rotation is measured in degrees clockwise
from the default position. When the marker is flat on the map, the default
position is North. When the marker is not flat, the default position is pointing
up and the rotation is such that the marker is always facing the camera.
The below example rotates the marker 90°. Setting the anchor point to
0.5,0.5 causes the marker to be rotated around its center, instead of its
static final LatLng PERTH = new LatLng(-31.90, 115.86); Marker perth = mMap.addMarker(new MarkerOptions() .position(PERTH) .anchor(0.5,0.5) .rotation(90.0));
Video: Animating markers
For more videos like these, visit the Google Maps Developers Live page.
The Maps API allows you to listen and respond to marker events. To listen to
these events, you must set the corresponding listener on the
object to which the markers belong. When the event occurs on one of the
markers on the map, the listener's callback will be invoked with the
Marker object passed through as a parameter. To compare this
Marker object with your own reference to a
Marker object, you must use
equals() and not
You can listen to the following events:
- Marker click events
- Marker drag events
- Info window click events
Marker click events
You can use an
OnMarkerClickListener to listen
for click events on the marker. To set this listener on the map, call
GoogleMap.setOnMarkerClickListener(OnMarkerClickListener). When a user
clicks on a marker,
onMarkerClick(Marker) will be called and the marker will
be passed through as an argument. This method returns a boolean that indicates
whether you have consumed the event (i.e., you want to suppress the default
behavior). If it returns
false, then the default behavior will occur in
addition to your custom behavior. The default behavior for a marker click
event is to show its info window (if available) and move the
camera such that the marker is centered on the map.
Marker drag events
You can use an
OnMarkerDragListener to listen for
drag events on a marker. To set this listener on the map, call
GoogleMap.setOnMarkerDragListener. To drag a marker, a user must long press
on the marker. When the user takes their finger off the screen, the marker
will stay in that position. When a marker is dragged,
onMarkerDragStart(Marker) is called initially. While the marker is being
onMarkerDrag(Marker) is called constantly. At the end of the drag
onMarkerDragEnd(Marker) is called. You can get the position of the marker at
any time by calling