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 />

Collision behavior controls how a marker displays if it collides (overlaps) with
another marker.

## Set the collision behavior for a marker


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

To set collision behavior, set
[`GMSAdvancedMarker.collisionBehavior`](https://developers.google.com/maps/documentation/ios-sdk/reference/objc/Classes/GMSAdvancedMarker.md.txt#collisionbehavior) to
one of the following:

- `GMSCollisionBehaviorRequired` (Default): Always display the marker
  regardless of collision. This is the default behavior. Has no impact on
  whether any other markers or basemap labels show.

- `GMSCollisionBehaviorOptionalAndHidesLowerPriority`: 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.

- `GMSCollisionBehaviorRequiredAndHidesOptional`: Always display the marker
  regardless of collision, and hide any
  `GMSCollisionBehaviorOptionalAndHidesLowerPriority`. Display the marker only
  if it does not overlap with other markers. Does not
  `GMSCollisionBehaviorRequired`. If two markers of this type would overlap,
  the one with the higher `zIndex` is shown. Collision rules for markers with
  the same `zIndex` are undefined.

  **Note:** For optimal collision behavior, create all advanced markers with the same type. This includes advanced markers represented with an [iconView](https://developers.google.com/maps/documentation/ios-sdk/advanced-markers/customization.md.txt#use_the_iconview_property), icon or default capabilities.

### Swift

```swift
// Defines a marker to always display and hide any marker or label overlay with this marker in the base map
marker.collisionBehavior = .requiredAndHidesOptional
```

### Objective-C

```objective-c
// Defines a marker to always display and hide any marker or label overlay with this marker in the base map
marker.collisionBehavior = GMSCollisionBehaviorRequiredAndHidesOptional
```