Is there any direct method or any suggestion on how to get all the annotations from the MKMapView
?
The easiest way to get an Integer of the current zoom level, is by using the MapView function: regionDidChangeAnimated. This function recognizes every change in zoom and will give you the basis for the calculation of the zoom factor.
The MKMapView class supports the ability to annotate the map with custom information. Because a map may have large numbers of annotations, map views differentiate between the annotation objects used to manage the annotation data and the view objects for presenting that data on the map.
Go to the storyboard. Drag a MapKit View to the main View. Give the MapKit View the same size as the main View. Select the MapKit View and go to the Pin button from the Auto Layout button on the bottom-right of the Storyboard and fill in the following values.
You can access map's annotations using its annotations
property. Getting views for all annotations may not be always possible as annotations that are not currently visible on the map may have no views associated with them, but for arbitrary annotation you can try to get a view using -viewForAnnotation:
method.
So here how you can iterate through all map's annotations and try to access their views:
for (id<MKAnnotation> annotation in mapView.annotations){ MKAnnotationView* anView = [mapView viewForAnnotation: annotation]; if (anView){ // Process annotation view ... } }
In swift 3.
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) { let selectedAnnotation = view.annotation for annotation in mapView.annotations { let viewI = mapView.view(for: annotation) if !(viewI?.annotation is MKUserLocation){ if annotation.isEqual(selectedAnnotation) { viewI?.image = UIImage(named: "focus.png") showLifeEventView(anotation: view) //did select a point on Map. }else{ viewI?.image = UIImage(named: "point.png") } } } }
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