Reputation: 1745
In my MKMapView I have this code:
let annotations = mapView.annotations(in: mapView.visibleMapRect)
let clusterAnnotations = annotations.compactMap { $0 as? MKClusterAnnotation }
This works and will populate clusterAnnotations
with the clusters currently visible.
However if I mess around with the map, zooming in and out (so the clusters are repeatably re-calculated); when I settle the map and re-run this code clusterAnnotations
will contain annotations that have been removed (de-clustered).
If I only look at the standard annotations, they are correct - the problem is only with the MKClusterAnnotation
.
I assume MapKit is holding on for efficiency; but how can I get only the clusters that are actually shown?
The code is run on a button click (rather than during map interaction), so I don't mind too much if the solution is a little slow...
Upvotes: 0
Views: 22