Почему мой код не удаляет аннотацию карты?
Я нажимаю кнопку, и она получает местоположение пользователя, а затем прикрепляет его к карте. Проблема в том, что когда кнопка нажимается второй, третий, ....... раз, он просто продолжает добавлять контакты вместо удаления первого контакта (имитируя замену контакта).
Я попытался добавить еще одну кнопку (очистить контакты) и следовать этой теме: /2788364/kak-udalit-vse-annotatsii-v-mkmapview, но приложение просто вылетает без информации отладки.
Но теоретически мой код должен работать. Так чего я не понимаю?
- (IBAction)getLocation:(id)sender {
MapAnnotation *ann1 =[[[MapAnnotation alloc] init]autorelease];
// remove annotation
[mapView removeAnnotation:ann1];
locationManager = [[CLLocationManager alloc] init];
locationManager.distanceFilter=kCLDistanceFilterNone;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters;
[locationManager startUpdatingLocation];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = {{0.0,0.0},{0.0,0.0}};
region.center.latitude = locationManager.location.coordinate.latitude;
region.center.longitude = locationManager.location.coordinate.longitude;
region.span.longitudeDelta = 0.005f;
region.span.latitudeDelta = 0.005f;
[mapView setRegion:region animated:YES];
[mapView setDelegate:sender];
MKCoordinateRegion location1;
location1.center.latitude =locationManager.location.coordinate.latitude;
location1.center.longitude= locationManager.location.coordinate.longitude;
location1.span.longitudeDelta=0.1;
location1.span.latitudeDelta =0.1;
// Add Annotation
//MapAnnotation *ann1 =[[MapAnnotation alloc] init];
ann1.title=@"You Parked Here";
ann1.subtitle=@"";
ann1.coordinate= location1.center;
[mapView addAnnotation:ann1];
}