Reputation: 1647
I'm trying to span a map to the center of two coordinates. It worked fine on previous versions of iOS, but now suddenly, I get this error message:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:nan, nan span:nan, nan>'
Any ideas on what's wrong?
CLLocationCoordinate2D savedCoordinate;
savedCoordinate.latitude = [userDef doubleForKey:@"savedCoordinate-latitude"];
savedCoordinate.longitude = [userDef doubleForKey:@"savedCoordinate-longitude"];
savedPosition = savedCoordinate;
CLLocationDistance visibleDistance = 100;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(savedCoordinate, visibleDistance, visibleDistance);
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:region];
[mapView setRegion:adjustedRegion animated:NO];
Upvotes: 1
Views: 1038
Reputation: 44876
The error message is telling you the problem: The coordinate you're specifying contains nan ("not a number") rather than a regular number.
If you log your coordinate pieces you should be able to find out the specifics. In particular, I'd be looking at savedCoordinate.latitude
and savedCoordinate.longitude
. Perhaps you're storing a string in the user defaults instead of a number? If the key doesn't exist in the user defaults, these should be 0 rather than nan.
See also:
Upvotes: 2