MKMapView NSInvalidArgumentException Invalid Region crash in ios6
I would rather suggest to use CLLocationCoordinate2DIsValid
so something like
guard CLLocationCoordinate2DIsValid(centerLat) else {
return
}
The problem is the center
coordinate:
+112.57075000, +37.87049600
The latitude must be from -90 to +90 so +112.57075 is out of range.
Check how the center coordinate is being set or maybe the data is backwards.
Also, you don't need to explicitly call regionThatFits
because the map view does it automatically when you set the region normally (ie. just call setRegion
). It's normal, by the way, for the map view to adjust the span as needed to fit the map view dimensions or zoom level.
I use the following code to set the region:
if( centerLat > -89 && centerLat < 89 && centerLng > -179 && centerLng < 179 ){
[self.mapView setRegion:region animated:YES];
}