I have a MapView displaying some annotations with displayPriority = .defaultHight
to allow automatic clustering.
The MapView also displays the current user location which has a default display priority of required
.
This causes my annotations to be hidden by the user location annotation when they are very close together.
I want to change this behavior by setting the display priority of the user location annotation to defaultLow
.
I tried using this approach:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
let userView = mapView.view(for: annotation)
userView?.displayPriority = .defaultLow
return userView
}
return mapView.view(for: annotation)
}
However userView
is always nil and therefore my displayPriority
modification is not applied.
Any ideas how the displayPriority
of the MKUserLocation
annotation view can be changed?