Cluster icon indicating copy to clipboard operation
Cluster copied to clipboard

mapView.showAnnotations breaks clustering

Open tomrapadmi opened this issue 5 years ago • 1 comments

Description Calling MKMapView.showAnnotations(:MKAnnotation) will zoom the map appropriately to show the annotations passed in, however the cluster manager will never cluster those annotations again (even after calling reload). I tried using the function in 2 ways:

  1. When a cluster is clicked: mapView.showAnnotations(clusterAnnotation.annotations, animated: true)
  2. When the annotations are initially created: mapView.showAnnotations(newAnnotations, animated: true)

In the first case the annotations from the cluster are never clustered again. In the second case no annotations are ever clustered.

Smartphone

  • Device: iPhone XR, iPhone 8
  • OS: iOS 12.2
  • Version: 3.0.0

Checklist

tomrapadmi avatar May 21 '19 16:05 tomrapadmi

For anyone struggling with this at this point.

I saw this issue as well. Judging from the behavior I observed with showAnnotations(), it will add the annotations to the mapview if they aren't already there, bypassing the Clustermanager completely. From the mapView's point of view this happens because it only knows about the CluserAnnotation and has no knowledge of its members.

My workaround was to calculate and generate the region of the annotations manually and then use MKMapView.setRegion(:MKCoordinateRegion) with that region. It will adjust the region without touching any annotations of the mapview.

spiegelsauce avatar Sep 26 '23 18:09 spiegelsauce