MKMapView NSInvalidArgumentException Invalid region error in ios6

The program crashes when setting location coordinates using MKMapView. Magazine:

Application termination due to an undetected exception "NSInvalidArgumentException", reason: "Invalid region <center:+112.57075000, +37.87049600 span:+0.05165163, +0.43945312> "

span in my program

 MKCoordinateSpan span; span.latitudeDelta = .05; span.longitudeDelta = .02; 

after coding:

  self.mMKMapview.region = [self.mMKMapview regionThatFits:region]; 

as the magazine shows, the range changes to: +0.05165163, +0.43945312

someone help, I stood here for two days.

Thanks!

+11
ios6 mkmapview
source share
3 answers

The problem is the center coordinate:

+112.57075000, +37.87049600

Latitude should be from -90 to +90, so +112.57075 is out of range.

Check the center coordinate setting, or maybe the data will be back.


In addition, you do not need to explicitly call regionThatFits , because the map display does this automatically when you usually set the region (i.e. just call setRegion ). This, by the way, is a normal map display to adjust the range as necessary to fit the size of the map or zoom level.

+15
source share

I use the following code to set the scope:

 if( centerLat > -89 && centerLat < 89 && centerLng > -179 && centerLng < 179 ){ [self.mapView setRegion:region animated:YES]; } 
+2
source share

I would better suggest using CLLocationCoordinate2DIsValid

so something like

 guard CLLocationCoordinate2DIsValid(centerLat) else { return } 
+1
source share

All Articles