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

<br />

This page shows you how to control the collision behavior for a marker.

## Set collision behavior for a marker


<iframe src="https://geo-devrel-javascript-samples.web.app/samples/advanced-markers-collision/app/dist/" allow="fullscreen; fullscreen"></iframe>

Collision behavior controls how a marker displays if it collides (overlaps)
with another marker. The way you create an advanced markers
determines how collision behavior works:

- Advanced markers created by using
  [`BitmapDescriptorFactory`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/BitmapDescriptorFactory.md.txt)
  are referred to as *bitmap* markers. These markers are drawn by the
  core map.

- All other advanced markers, including those created by
  using the `AdvancedMarkerOptions.iconView()` method, are referred to as
  *view* markers and are drawn on a layer above the core map.

> [!NOTE]
> **Note:** For optimal collision behavior, you should create all advanced markers of the same type. That is, if you are using a view marker for one marker then you should use view markers for all of them.

To set collision behavior, set
[`AdvancedMarkerOptions.collisionBehavior`](https://developers.google.com/android/reference/com/google/android/gms/maps/model/AdvancedMarkerOptions.md.txt#collisionBehavior(int))
to one of the following:

- `CollisionBehavior.REQUIRED`: (default) Always display the marker regardless of collision.
- `CollisionBehavior.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.
- `CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY` Display the marker
  only if it does not overlap with other markers.

  - If two *bitmap* markers 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. For more information about the `zIndex`, see [Marker
    z-index](https://developers.google.com/maps/documentation/android-sdk/marker#marker_z-index).

  - If two *view* markers overlap, the one with the higher `zIndex` is
    shown. If they have the same `zIndex`, the last created marker
    overlaps any markers created before it.

  - Because *view* markers are drawn on a layer above *bitmap* markers,
    *view* markers overlap *bitmap* markers. Therefore, you should try
    to use markers of the same type for better collision control.

The following example shows setting collision behavior for a marker:

### Kotlin

```kotlin
// Collision behavior can only be changed in the AdvancedMarkerOptions object.
// Changes to collision behavior after a marker has been created are not possible
val collisionBehavior: Int = CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL
val advancedMarkerOptions: AdvancedMarkerOptions = AdvancedMarkerOptions()
    .position(LatLng(10.0, 10.0))
    .collisionBehavior(collisionBehavior)

val marker: Marker = map.addMarker(advancedMarkerOptions) ?: error("Failed to add marker")

      
```

### Java

```java
// Collision behavior can only be changed in the AdvancedMarkerOptions object.
// Changes to collision behavior after a marker has been created are not possible
int collisionBehavior = AdvancedMarkerOptions.CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL;
AdvancedMarkerOptions options =
        new AdvancedMarkerOptions()
                .position(new LatLng(10.0, 10.0))
                .collisionBehavior(collisionBehavior);

Marker marker = map.addMarker(options);

      
```

<br />