Search code examples
ios6mkmapview

MKMapView NSInvalidArgumentException Invalid Region crash in ios6


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!


Solution

  • 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.