Sam D20
Sam D20

Reputation: 2575

XCode not accepting my CLLocationCoordinate2D. Says "invalid region"

CLLocationCoordinate2D defaultCoordinate;
defaultCoordinate.latitude = 47.517201;
defaultCoordinate.longitude = -120.366211;
[locationView setRegion:MKCoordinateRegionMake(defaultCoordinate,   MKCoordinateSpanMake(250, 250)) animated:NO];  

I make a CLLocationCoordinate2D, set its coordinates, and then I simultaneously create a MKCoordinateRegion and set the region of my map view locationView.

This is the error I am getting:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid Region <center:+47.51720100, -120.36621100 span:+250.00000000, +250.00000000>'

Anyone know why it is giving me this error? I'm fairly sure the coordinates are valid.

Upvotes: 0

Views: 617

Answers (1)

zimmryan
zimmryan

Reputation: 1099

MKCoordinateSpan accepts a range in degrees longitude and degrees latitude. You are passing it 250,250. The entire earths longitude only goes from -180 to 180 and latitude from -90 to 90. You need to convert what I am assuming is a measurement of 250 meters to longitude and latitude.

Or alternatively use the function MKCoordinateRegionMakeWithDistance

MKCoordinateRegion MKCoordinateRegionMakeWithDistance(
   CLLocationCoordinate2D centerCoordinate,
   CLLocationDistance latitudinalMeters,
   CLLocationDistance longitudinalMeters
);

Upvotes: 2

Related Questions