Question: How do I prevent an MKClusterAnnotation
from displaying a callout?
Background: I'm a beginner at programming, please be gentle. I'm trying to make a MapKit-based app which shows a number of sites on a map. I have populated the map with dummy locations from a GeoJSON, which works fine. However, while callouts make sense from individual annotations, I would rather not have them appear from a cluster annotation. I haven't been able to figure ot how to remove callouts from clusters.
My annotations are created like so:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
} else {
let identifier = "site"
var marker: MKMarkerAnnotationView
if let dequeuedView = mapView.dequeueReusableAnnotationView(
withIdentifier: identifier) as? MKMarkerAnnotationView {
dequeuedView.annotation = annotation
marker = dequeuedView
} else {
marker = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
}
marker.canShowCallout = true // How can I turn this false if callout is a cluster?
marker.markerTintColor = .systemBlue
marker.rightCalloutAccessoryView = UIButton(type: .detailDisclosure)
marker.glyphImage = UIImage(systemName: "star")
marker.clusteringIdentifier = "clusteringIdentifier"
return marker
}
}
And here is my MKClusterAnnotation:
func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
let cluster = MKClusterAnnotation(memberAnnotations: memberAnnotations)
cluster.title = "More things to see here"
cluster.subtitle = "Zoom further in"
return cluster
}
This is probably incredibly simple, but I wasn't able to find it out on my own (or by looking at Apple docs). Any help is appreciated! (Also if you see anything silly in my code, don't be afraid to point it out).