Reputation: 2575
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
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