AI-generated Key Takeaways
- 
          Collision behavior dictates how markers are displayed when they overlap on the map. 
- 
          You can configure a marker's collision behavior using the GMSAdvancedMarker.collisionBehaviorproperty with three options:GMSCollisionBehaviorRequired,GMSCollisionBehaviorOptionalAndHidesLowerPriority, andGMSCollisionBehaviorRequiredAndHidesOptional.
- 
          GMSCollisionBehaviorRequiredis the default, always displaying the marker regardless of overlap.
- 
          GMSCollisionBehaviorOptionalAndHidesLowerPrioritydisplays the marker only if it doesn't overlap with others, prioritizing higherzIndexand lower screen position in case of conflicts.
- 
          GMSCollisionBehaviorRequiredAndHidesOptionalalways displays the marker and hides any withGMSCollisionBehaviorOptionalAndHidesLowerPrioritybehavior.
Collision behavior controls how a marker displays if it collides (overlaps) with another marker.
Set the collision behavior for a marker
To set collision behavior, set
GMSAdvancedMarker.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- zIndexis 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- zIndexis shown. Collision rules for markers with the same- zIndexare undefined.
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
// Defines a marker to always display and hide any marker or label overlay with this marker in the base map marker.collisionBehavior = GMSCollisionBehaviorRequiredAndHidesOptional