MKMapView NSInvalidArgumentException Invalid Region crash in ios6
Asked Answered
R

3

14

Program crashes when set location coordinates using MKMapView. Log:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+112.57075000, +37.87049600 span:+0.05165163, +0.43945312>'

span in my program is

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

after coding:

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

as the log shows, span changes to :+0.05165163, +0.43945312

anyone help please, I have been standstill here for two days.

Thanks!

Ruffi answered 27/10, 2012 at 12:35 Comment(0)
L
21

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.

Leitmotiv answered 27/10, 2012 at 13:35 Comment(0)
P
4

I would rather suggest to use CLLocationCoordinate2DIsValid

so something like

guard CLLocationCoordinate2DIsValid(centerLat) else {

     return
}
Partridgeberry answered 26/7, 2019 at 16:50 Comment(0)
G
3

I use the following code to set the region:

if( centerLat > -89 && centerLat < 89 && centerLng > -179 && centerLng < 179 ){
    [self.mapView setRegion:region animated:YES];
}
Gondar answered 14/10, 2015 at 11:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.