I have to remove all the annotations added to my MKMapView but when I execute :
NSMutableArray *annotationsToRemove = [[NSMutableArray alloc] initWithArray: mapView.annotations];
[mapView removeAnnotations: annotationsToRemove];
The array annotationsToRemove contains a MKUserLocation
annotation and it doesn't delete it.
Is there a way to reset the map? I need to delete all the annotations from it!
In the h insert
In the m insert
You can just set the showsUserLocation property of your mapView to NO.
Actually you can not edit
MKUserLocation
annotation. I mean you can not remove it from map annotation's array as it is aread-only
property ofMKMapView
.If you visit
MKMapView.h
class. You will find below lineHere we can see that this property is a read only. So we can not delete it from
MKMapView
annotations array. How ever you face difficulties in calculation with other annotations then you can runtime hide it.What I am trying to explain is when user location is not required any more you can set
NO
for user location property.For example with your code:
Check
NSLog
output, you will see thatMKUserLocation
annotation is removed frommapView.annotations
array.It is the simple way I did follow. How ever I am not sure about there is other way to do this. Please leave a comment if you found any other solution.