I need to count number of annotations when i zooming mapView, and get array with which are shown on map, and then, i need to reload my Table and show list of only which shown on map.
How can i get number and array with annotation?
David's great solution in Swift 4
extension MKMapView {
func visibleAnnotations() -> [MKAnnotation] {
return self.annotations(in: self.visibleMapRect).map { obj -> MKAnnotation in return obj as! MKAnnotation }
}
}
As for swift 2.0, I usually use this mapView extension to get all currently visible annotations as an array of MKAnnotations:
extension MKMapView {
func visibleAnnotations() -> [MKAnnotation] {
return self.annotationsInMapRect(self.visibleMapRect).map { obj -> MKAnnotation in return obj as! MKAnnotation }
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With