Cluster is an easy map annotation clustering library. This repository uses an efficient method (QuadTree) to aggregate pins into a cluster.
You may want to see the Example first if you'd like to see the actual code.
$ pod try Cluster
- iOS 8.0+
- Xcode 8.0+
- Swift 3.0+
Follow the instructions below:
let clusterManager = ClusterManager()
let annotation = Annotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
clusterManager.add(annotation)
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var view = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
if view == nil {
view = ClusterAnnotationView(annotation: annotation, reuseIdentifier: identifier, type: .color(color: color, radius: radius))
} else {
view?.annotation = annotation
}
return view
}
func mapView(_ mapView: MKMapView, regionDidChangeAnimated animated: Bool) {
clusterManager.reload(mapView)
}
To install with CocoaPods, simply add this in your Podfile
:
use_frameworks!
pod "Cluster"
To install with Carthage, simply add this in your Cartfile
:
github "efremidze/Cluster"
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
https://github.com/ribl/FBAnnotationClusteringSwift
Cluster is available under the MIT license. See the LICENSE file for more info.