Select platform: [Android](https://developers.google.com/maps/documentation/android-sdk/marker.md.txt "View this page for the Android platform docs.") [iOS](https://developers.google.com/maps/documentation/ios-sdk/marker.md.txt "View this page for the iOS platform docs.") [JavaScript](https://developers.google.com/maps/documentation/javascript/markers.md.txt "View this page for the JavaScript platform docs.")

<br />

![A map with several markers](https://developers.google.com/static/maps/documentation/android-sdk/examples/images/advanced-marker.png)

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`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker.md.txt), and are added to the map with the
`GoogleMap.addMarker(markerOptions)` method.

Markers are designed to be interactive. They receive `click` events by
default, and are often used with event listeners to bring up [info
windows](https://developers.google.com/maps/documentation/android-sdk/infowindows). Setting a marker's `draggable` property to `true`
allows the user to change the position of the marker. Use a long press to
activate the ability to move the marker.

By default, when a user taps a marker, the map toolbar appears at the bottom
right of the map, giving the user quick access to the Google Maps mobile app.
You can disable the toolbar. For more information, see the
[guide to controls](https://developers.google.com/maps/documentation/android-sdk/controls.md.txt#toolbar).

## Add a marker

The following example demonstrates how to add a marker to a map. The marker is
created at coordinates `-33.852,151.211` (Sydney, Australia), and displays the
string 'Marker in Sydney' in an info window when clicked.


### Kotlin

```kotlin
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
val sydney = LatLng(-33.852, 151.211)
map.addMarker(
    MarkerOptions()
        .position(sydney)
        .title("Marker in Sydney"),
)
map.moveCamera(CameraUpdateFactory.newLatLng(sydney))

      
```

### Java

```java
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
LatLng sydney = new LatLng(-33.852, 151.211);
map.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
map.moveCamera(CameraUpdateFactory.newLatLng(sydney));

      
```

<br />

## Display additional information about a marker

A common requirement is to show additional information about a place or
location when the user taps a marker on the map. See the guide to
[info windows](https://developers.google.com/maps/documentation/android-sdk/infowindows.md.txt).

## Associate data with a marker

You can store an arbitrary data object with a marker using `Marker.setTag()`,
and retrieve the data object using `Marker.getTag()`. The sample below shows how
you can count the number of times a marker has been clicked using tags:


### Kotlin

```kotlin
val PERTH = LatLng(-31.952854, 115.857342)
val SYDNEY = LatLng(-33.87365, 151.20689)
val BRISBANE = LatLng(-27.47093, 153.0235)

val markerPerth = map.addMarker(
    MarkerOptions()
        .position(PERTH)
        .title("Perth"),
)
markerPerth?.tag = 0

val markerSydney = map.addMarker(
    MarkerOptions()
        .position(SYDNEY)
        .title("Sydney"),
)
markerSydney?.tag = 0

val markerBrisbane = map.addMarker(
    MarkerOptions()
        .position(BRISBANE)
        .title("Brisbane"),
)
markerBrisbane?.tag = 0

// Set a listener for marker click.
map.setOnMarkerClickListener { marker ->
    // Retrieve the data from the marker.
    val clickCount = marker.tag as? Int

    // Check if a click count was set, then display the click count.
    clickCount?.let {
        val newClickCount = it + 1
        marker.tag = newClickCount
        Toast.makeText(
            context,
            "${marker.title} has been clicked $newClickCount times.",
            Toast.LENGTH_SHORT,
        ).show()
    }

    // Return false to indicate default behavior.
    false
}

      
```

### Java

```java
final LatLng PERTH = new LatLng(-31.952854, 115.857342);
final LatLng SYDNEY = new LatLng(-33.87365, 151.20689);
final LatLng BRISBANE = new LatLng(-27.47093, 153.0235);

Marker markerPerth = map.addMarker(new MarkerOptions().position(PERTH).title("Perth"));
markerPerth.setTag(0);

Marker markerSydney = map.addMarker(new MarkerOptions().position(SYDNEY).title("Sydney"));
markerSydney.setTag(0);

Marker markerBrisbane =
        map.addMarker(new MarkerOptions().position(BRISBANE).title("Brisbane"));
markerBrisbane.setTag(0);

// Set a listener for marker click.
map.setOnMarkerClickListener(
        new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(final Marker marker) {
                // Retrieve the data from the marker.
                Integer clickCount = (Integer) marker.getTag();

                // Check if a click count was set, then display the click count.
                if (clickCount != null) {
                    clickCount = clickCount + 1;
                    marker.setTag(clickCount);
                    Toast.makeText(
                                    context,
                                    marker.getTitle()
                                            + " has been clicked "
                                            + clickCount
                                            + " times.",
                                    Toast.LENGTH_SHORT)
                            .show();
                }

                // Return false to indicate default behavior should occur.
                return false;
            }
        });

      
```

<br />

Here are some examples of scenarios when it's useful to store and retrieve data
with markers:

- Your app may cater for different types of markers, and you want to treat them differently when the user clicks them. To accomplish this, you can store a `String` with the marker indicating the type.
- You may be interfacing with a system that has unique record identifiers, where the markers represent specific records in that system.
- Marker data may indicate a priority to be used when deciding the z-index of a marker.

## 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
that position.

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](https://developers.google.com/maps/documentation/android-sdk/marker#marker_drag_events).

The below snippet adds a draggable marker at Perth, Australia.


### Kotlin

```kotlin
val perthLocation = LatLng(-31.90, 115.86)
val perth = map.addMarker(
    MarkerOptions()
        .position(perthLocation)
        .draggable(true),
)

      
```

### Java

```java
final LatLng perthLocation = new LatLng(-31.90, 115.86);
Marker perth = map.addMarker(new MarkerOptions().position(perthLocation).draggable(true));

      
```

<br />

## Customize a marker

This video shows ways of using markers to visualize locations on a map.
[Video](https://www.youtube.com/watch?v=FFm9NmSfjw0)

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)
:   The `LatLng`
    value for the marker's position on the map. This is the only required
    property for a `Marker` object.

Anchor
:   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.

Alpha
:   Sets the opacity of the marker. Defaults to 1.0.

Title
:   A string that's displayed in the info window when the user taps the
    marker.

Snippet
:   Additional text that's displayed below the title.

Icon
:   A bitmap that's displayed in place of the default marker image.

Draggable
:   Set to `true` if you want to allow the user to move
    the marker. Defaults to `false`.

Visible
:   Set to `false` to make the marker invisible. Defaults to
    `true`.

Flat or Billboard orientation
:   By default, markers use a billboard orientation, meaning they are drawn
    oriented against the device's screen rather than against the map's surface.
    Rotating, tilting, or zooming the map does not change the orientation of the
    marker. You can set the orientation of a marker to be flat against the earth.
    Flat markers rotate when the map is rotated, and change perspective when the
    map is tilted. As with billboard markers, flat markers retain their size when
    the map is zoomed in or out.

Rotation
:   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.


### Kotlin

```kotlin
val melbourneLocation = LatLng(-37.813, 144.962)
val melbourne = map.addMarker(
    MarkerOptions()
        .position(melbourneLocation),
)

      
```

### Java

```java
final LatLng melbourneLocation = new LatLng(-37.813, 144.962);
Marker melbourne = map.addMarker(new MarkerOptions().position(melbourneLocation));

      
```

<br />

### 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 [`BitmapDescriptorFactory`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.md.txt)
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.


### Kotlin

```kotlin
val melbourneLocation = LatLng(-37.813, 144.962)
val melbourne = map.addMarker(
    MarkerOptions()
        .position(melbourneLocation)
        .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)),
)

      
```

### Java

```java
final LatLng melbourneLocation = new LatLng(-37.813, 144.962);
Marker melbourne =
        map.addMarker(
                new MarkerOptions()
                        .position(melbourneLocation)
                        .icon(
                                BitmapDescriptorFactory.defaultMarker(
                                        BitmapDescriptorFactory.HUE_AZURE)));

      
```

<br />

### 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.


### Kotlin

```kotlin
val melbourneLocation = LatLng(-37.813, 144.962)
val melbourne = map.addMarker(
    MarkerOptions()
        .position(melbourneLocation)
        .alpha(0.7f),
)

      
```

### Java

```java
final LatLng melbourneLocation = new LatLng(-37.813, 144.962);
Marker melbourne =
        map.addMarker(new MarkerOptions().position(melbourneLocation).alpha(0.7f));

      
```

<br />

### 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 `BitmapDescriptor`, and
defined using one of the methods in the
[`BitmapDescriptorFactory`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.md.txt) class.

`fromAsset(String assetName)`
:   Creates a custom marker using the name of a Bitmap image in the assets
    directory.

`fromBitmap(Bitmap image)`
:   Creates a custom marker from a Bitmap image.

`fromFile(String fileName)`
:   Creates a custom icon using the name of a Bitmap image file located in the
    internal storage.

`fromPath(String absolutePath)`
:   Creates a custom marker from an absolute file path of a Bitmap image.

`fromResource(int resourceId)`
:   Creates a custom marker using the resource ID of a Bitmap image.

The below snippet creates a marker with a custom icon.


### Kotlin

```kotlin
val melbourneLocation = LatLng(-37.813, 144.962)
val melbourne = map.addMarker(
    MarkerOptions()
        .position(melbourneLocation)
        .title("Melbourne")
        .snippet("Population: 4,137,400")
        .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)),
)

      
```

### Java

```java
final LatLng melbourneLocation = new LatLng(-37.813, 144.962);
Marker melbourne =
        map.addMarker(
                new MarkerOptions()
                        .position(melbourneLocation)
                        .title("Melbourne")
                        .snippet("Population: 4,137,400")
                        .icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));

      
```

<br />

### 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
`true`.


### Kotlin

```kotlin
val perthLocation = LatLng(-31.90, 115.86)
val perth = map.addMarker(
    MarkerOptions()
        .position(perthLocation)
        .flat(true),
)

      
```

### Java

```java
final LatLng perthLocation = new LatLng(-31.90, 115.86);
Marker perth = map.addMarker(new MarkerOptions().position(perthLocation).flat(true));

      
```

<br />

### Rotate a marker

You can rotate a marker around its anchor point with the
`Marker`.`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
base.


### Kotlin

```kotlin
val perthLocation = LatLng(-31.90, 115.86)
val perth = map.addMarker(
    MarkerOptions()
        .position(perthLocation)
        .anchor(0.5f, 0.5f)
        .rotation(90.0f),
)

      
```

### Java

```java
final LatLng perthLocation = new LatLng(-31.90, 115.86);
Marker perth =
        map.addMarker(
                new MarkerOptions()
                        .position(perthLocation)
                        .anchor(0.5f, 0.5f)
                        .rotation(90.0f));

      
```

<br />

## Marker z-index

The z-index specifies the stack order of this marker, relative to other markers
on the map. A marker with a high z-index is drawn on top of markers with lower
z-indexes. The default z-index value is `0`.

Set the z-index on the marker's options object by calling
`MarkerOptions.zIndex()`, as shown in the following code snippet:


### Kotlin

```kotlin
map.addMarker(
    MarkerOptions()
        .position(LatLng(10.0, 10.0))
        .title("Marker z1")
        .zIndex(1.0f),
)

      
```

### Java

```java
map.addMarker(
        new MarkerOptions().position(new LatLng(10, 10)).title("Marker z1").zIndex(1.0f));

      
```

<br />

You can access the marker's z-index by calling `Marker.getZIndex()`, and you can
change it by calling `Marker.setZIndex()`.

Markers are always drawn above tile layers and other non-marker overlays (ground
overlays, polylines, polygons, and other shapes) regardless of the z-index of
the other overlays. Markers are effectively considered to be in a separate
z-index group compared to other overlays.

Read about [the effect of z-index on click events](https://developers.google.com/maps/documentation/android-sdk/marker.md.txt#click-index) below.

## Handle marker events

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 `GoogleMap`
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
corresponding `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](https://developers.google.com/maps/documentation/android-sdk/marker.md.txt#marker_click_events)
- [Marker drag events](https://developers.google.com/maps/documentation/android-sdk/marker.md.txt#marker_drag_events)
- [Info window click events](https://developers.google.com/maps/documentation/android-sdk/infowindows.md.txt#info_window_events)

### Marker click events

You can use an [`OnMarkerClickListener`](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMarkerClickListener.md.txt) 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](https://developers.google.com/maps/documentation/android-sdk/infowindows.md.txt) (if available) and move the
camera such that the marker is centered on the map.


Effect of z-index on click events:

- When a user clicks on a cluster of markers, the click event is triggered for the marker with the highest z-index.
- At most one event is triggered per click. In other words, the click is not passed down to the markers or other overlays with lower z-index values.
- Clicking on a cluster of markers causes subsequent clicks to cycle through the cluster, selecting each in turn. The order of the cycle first prioritises z-index, then proximity to the click point.
- If the user clicks outside the proximity of the cluster, the API recalculates the cluster and resets the state of the click cycle so that it starts from the beginning.
- Markers are effectively considered to be in a separate z-index group compared to other overlays or shapes (polylines, polygons, circles, and/or ground overlays), regardless of the z-index of the other overlays. If multiple markers, overlays or shapes are overlaid on top of each other, the click event is cycled through the cluster of markers first.

### Marker drag events

You can use an [`OnMarkerDragListener`](https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap.OnMarkerDragListener.md.txt) 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
dragged, `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 `Marker.getPosition()`.

> [!NOTE]
> **Note:** By default, a marker is not draggable. A marker must explicitly be set to be draggable before it can be dragged by a user. This can be done either with `MarkerOptions.draggable(boolean)` prior to adding it to the map, or `Marker.setDraggable(boolean)` once it has been added to the map.