1

I have added clustering with annotations in my project and it's working fine but having problem to set the limit.
Please check below image here, grouping is done for 6 annotations but I want to set clustering limit which should start grouping at 20 (So never see one of these with the number 19 or lower)

enter image description here

  func mapView(_ mapView: MKMapView, clusterAnnotationForMemberAnnotations memberAnnotations: [MKAnnotation]) -> MKClusterAnnotation {
       return MKClusterAnnotation(memberAnnotations: memberAnnotations)
    }

Also I tried this but not working for me.

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {

    let groupedpin = annotation as! MKClusterAnnotation

        if groupedpin.memberAnnotations.count >= 20 { //<— Not working
            let view = PlaceClusterAnnotationView.annotationView()
            view._count = groupedpin.memberAnnotations.count.description
            return view
        } 
   return MKAnnotationView()
}
PPL
  • 6,357
  • 1
  • 11
  • 30

1 Answers1

1

You cannot force annotations to cluster, but you can prevent annotations from clustering. Do not give any view a clusteringIdentifier (meaning, set it to nil to prevent clustering; an empty string "" still acts as a clustering identifier) until you want it to be able to cluster, and keep the view's displayPriority at required until you want it to be able to cluster. To try to make a view cluster, set its displayPriority to 0. If you suddenly set twenty views' displayPriority to 0 then if they are close enough together they will probably all cluster. But you can't guarantee this.

tukool
  • 109
  • 1
  • 1
  • 10
matt
  • 515,959
  • 87
  • 875
  • 1,141