Hide information under map annotation

70 Views Asked by At

The default MapMarker hides information that is under it, for example a city name. If zoomed closed enough the marker doesn't cover the name anymore and the name is displayed. When using a custom annotation view both the city name and the annotation is displayed, it looks a lil messy. Is it possible to get the behaviour from MapMarker when using custom annotations? MapMarker: https://i.stack.imgur.com/OhQxj.png Custom: https://i.stack.imgur.com/GwO23.png

Maybe something with clustering or collisions, but seems do be annotations colliding with annotations.

1

There are 1 best solutions below

0
albstr On BEST ANSWER

setting the value of .displayPriority to some value seems to do the trick. Don't know which value to set though.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    let annotation = MKAnnotationView(annotation: annotation, reuseIdentifier: "annotation")
    annotation.image = UIImage(systemName: "circle.fill")
    annotation.frame = CGRect(x: 0, y: 0, width: 50, height: 50)
    annotation.displayPriority = .defaultHigh
            
    return annotation
}