First of all there is only user location in MKMapView. After some actions I call method:
[self mapView:self.mapView didAddAnnotationViews:self.pointersArray];
My didAddAnnotationViews
method:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
if (views.count == 1) {
MKAnnotationView *annotationView = [views objectAtIndex:0];
id<MKAnnotation>mp = [annotationView annotation];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate], 500, 500);
[mapView setRegion:region animated:YES];
}
else {
[mapView addAnnotations:views];
}
}
Application is not crashing until zoom is not used. But when zoom used more then 10 times (about) I get error in this [mapView addAnnotations:views];
or sometimes in return UIApplicationMain(argc, argv, nil, NSStringFromClass([BIDAppDelegate class]));
. Error - EXC_BAD_ACCESS
. There is my problem?
EDIT
Changed to [self.mapView setRegion:region animated:YES];
But now I have error in main thread MKNormalizedPointForLayer EXC_BAD_ACCESS
. In generally zoom is working, applications crashes after using zoom for example 7 or more times..
My button's action:
- (void)showKantorsOnMap {
if (self.kantorsData.count != self.pointersArray.count) {
NSLog(@"need to wait more");
}
NSMutableArray *toRemove = [[NSMutableArray alloc] init];
for (id annotation in self.mapView.annotations)
if (annotation != self.mapView.userLocation)
[toRemove addObject:annotation];
[self.mapView removeAnnotations:toRemove];
[self.mapView addAnnotations:self.pointersArray];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(self.mapView.userLocation.coordinate,6500, 6500);
[self.mapView setRegion:region animated:YES];
}
SOLUTION
Problem was in didAddAnnotationViews
method [mapView addAnnotations:views];
called recursion.