Dezoom programmatically crash

108 Views Asked by At

I have a zoom / dezoom button on a MKMapView. Zooming is working but dezoom is crashing when the user is at the max dezoom level. I have the exception :

'NSInvalidArgumentException', reason: 'Invalid Region <center:+37.17818069, -96.05458069 span:+237.74976671, +218.02936959>'

Sometimes with NaN values. How can I check the validity of next region ?

Here's my code

MKCoordinateRegion region = self.mapView_apple.region;
region.span.latitudeDelta *= 2.0;
region.span.longitudeDelta *= 2.0;
self.mapView_apple.region = region;
1

There are 1 best solutions below

0
On

So based on Chan's comment here is my solution :

MKCoordinateRegion region = self.mapView.region;
MKCoordinateSpan newSpan = region.span;
newSpan.latitudeDelta *= 2.0; // divide for zooming and change the value if you want
newSpan.longitudeDelta *= 2.0;
if(newSpan.latitudeDelta < 180.f && newSpan.longitudeDelta < 180.f) {
    region.span = newSpan;
    [self.mapView setRegion:region animated:YES];
}

Thanks !