Configure marker collision behavior

Select platform: Android iOS JavaScript

You can specify how a marker should behave when it collides with another marker or map label by setting the collisionBehavior property to one of the following values:

  • REQUIRED: The marker should always be displayed regardless of collisions.
  • REQUIRED_AND_HIDES_OPTIONAL: The marker should always be displayed regardless of collisions. Markers with OPTIONAL_AND_HIDES_LOWER_PRIORITY collision behavior r the default map labels that overlap with this marker will be hidden.
  • OPTIONAL_AND_HIDES_LOWER_PRIORITY: The marker should only be displayed if it does not overlap with other markers. If two markers of this type would overlap, the one with the higher draw order is shown. If they have the same draw order, the one with the lower vertical screenposition is shown.

The following code sample demonstrates each of the collision behavior values. To use this code sample, follow the instructions in Setup and Add a 3D map to your app to set up your Android Studio project with a basic 3D map. Then, add the following code to the MainActivity.kt file:

// Add imports
importcom.google.android.gms.maps3d.model.latLngAltitude
...
// Marker 1: REQUIRED
googleMap3D.addMarker(markerOptions{
position=latLngAltitude{
latitude=52.52027645136134
longitude=13.408271658592406
altitude=0.0
}
label="Collision Behavior: REQUIRED"
altitudeMode=AltitudeMode.CLAMP_TO_GROUND
isExtruded=true
isDrawnWhenOccluded=true
collisionBehavior=CollisionBehavior.REQUIRED
})
// Marker 2: REQUIRED_AND_HIDES_OPTIONAL
googleMap3D.addMarker(markerOptions{
position=latLngAltitude{
latitude=52.519605780912585
longitude=13.406867190588198
altitude=150.0
}
label="Colliding Behavior: REQUIRED_AND_HIDES_OPTIONAL"
altitudeMode=AltitudeMode.ABSOLUTE
isExtruded=true
isDrawnWhenOccluded=true
collisionBehavior=CollisionBehavior.REQUIRED_AND_HIDES_OPTIONAL
})
// Marker 3: OPTIONAL_AND_HIDES_LOWER_PRIORITY
googleMap3D.addMarker(markerOptions{
position=latLngAltitude{
latitude=52.519882191069016
longitude=13.407410777254293
altitude=50.0
}
label="Colliding Behavior: OPTIONAL_AND_HIDES_LOWER_PRIORITY"
altitudeMode=AltitudeMode.RELATIVE_TO_GROUND
isExtruded=true
isDrawnWhenOccluded=true
collisionBehavior=CollisionBehavior.OPTIONAL_AND_HIDES_LOWER_PRIORITY
})

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年11月21日 UTC.