ribl / FBAnnotationClusteringSwift

Swift translation of FB Annotation Clustering, which clusters pins on the map for iOS.
http://ribl.co/blog/2015/05/28/map-clustering-with-swift-how-we-implemented-it-into-the-ribl-ios-app/
MIT License
311 stars 109 forks source link

How to identify how many annotations does a cluster annotation has #64

Closed mvorisis closed 7 years ago

mvorisis commented 7 years ago

Hi

I'm trying to zoom in when the user taps on a cluster annotation, and now I did that I want to zoom in differently depends on how many annotations does the cluster annotation that I tapped has clustered.

Thanks in advance

mvorisis commented 7 years ago

I found it out!

Inside didselectannotation I put these lines of code:

if view.annotation!.isKindOfClass(FBAnnotationCluster)
        {
            let pinToZoomOn = view.annotation as! FBAnnotationCluster
//this is for getting the number of clustered annotations
            print(pinToZoomOn.annotations.count)

//Then depends of how many there are you can zoom differently            
            let span = MKCoordinateSpanMake(0.010, 0.010)

            let region = MKCoordinateRegion(center: pinToZoomOn.coordinate, span: span)
            mapView.setRegion(region, animated: true)
        }