3 Replies
      Latest reply on Sep 11, 2019 12:00 PM by StephaniesHusband
      DaleOne Level 1 Level 1 (0 points)

        Hi!

         

        I noticed a strange behavior on MapKit when using the iOS 11 clustering feature.

         

        If you add some annotations on a map (with same clusteringIdentifier and same displayPriority) MapKit will correctly merge together annotations that are close.

        The problem is that if you remove all the annotations and then you add them back the map will no more merge the annotation together. It’s like the clustering feature simply stop working.

         

        I don’t really know if it is a bug or if I miss something.

        Someone else have noticed this?

         

        Alan

        • Re: Clustering stop working after removing all annotations
          gasho Level 1 Level 1 (0 points)

          Hey!

           

          I have exactly the same issue. Did you find a way to fix it?

            • Re: Clustering stop working after removing all annotations
              DaleOne Level 1 Level 1 (0 points)

              Hi gasho!

               

              I found a temporary fix for the problem that seems to work in my particular situation.

               

              After removing all the annotations I change the cluster identifier of the annotations before adding them back. If the cluster identifier change then the clustering seems to start working again.

               

              For example if the cluster identifier of the annotations is "place", after removing the annotations you can try to set the cluster identifier to "place-2". When you add them back on the map they should cluster again.

               

              Hope this bug will be fixed soon.

               

              Alan

              • Re: Clustering stop working after removing all annotations
                StephaniesHusband Level 1 Level 1 (0 points)

                I know this is an old post, but I found a solution and thought I would post my solution for posterity.  I had the same issue and found a solution better than (re)setting a completely different clusteringIdentifier as suggested.  Like me, you were probably setting it in the init of your annotation view which never gets called after initializing.  I moved the setting of the clusteringIdentifier to the mapView(viewFor) delegate and it works perfectly now.

                 

                func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
                   let view = self.map.dequeueReusableAnnotationView(withIdentifier: NSStringFromClass(SADevice.self), for: annotation)
                
                   view.clusteringIdentifier = "cluster"
                
                   return view
                }