This page shows you how to manage collisions between markers that you add to your map and default labels, such as points of interest (POIs) or street names.
Before you begin
To manage marker and label collisions, you must be using a map id.
Specifying marker priorities
collisionBehavior property to specify priority on a
Use one of the following values:
Required- Default. Requires display of a marker that overlaps with other markers, labels, and POIs.
OptionalAndHidesLowerPriority- Indicates that the marker may be replaced or overlapped by a required marker, or replaced by an
OptionalAndHidesLowerPrioritymarker with higher priority. Use
zIndexto help determine relative priority between
OptionalAndHidesLowerPrioritymarkers. A higher
zIndexvalue indicates higher priority.
RequiredAndHidesOptional- Requires display of a marker while hiding any
OptionalAndHidesLowerPrioritymarkers, labels, or POIs that overlap with the marker. The marker may overlap with other required markers.
The following code example shows setting
collisionBehavior for a new marker:
let position = CLLocationCoordinate2D(latitude: 47.0169, longitude: -122.336471) let marker = GMSMarker(position: position) marker.zIndex = 10 marker.collisionBehavior = GMSCollisionBehavior.optionalAndHidesLowerPriority marker.map = mapView
CLLocationCoordinate2D position = CLLocationCoordinate2DMake(47.0169, -122.336471); GMSMarker *marker = [GMSMarker markerWithPosition:position]; marker.zIndex = 10; marker.collisionBehavior = GMSCollisionBehaviorOptionalAndHidesLowerPriority; marker.map = mapView;