I have two coordinates:
@property (assign) CLLocationCoordinate2D coordinate1;
@property (assign) CLLocationCoordinate2D coordinate2;
During init I'm making them invalid (to be able to check later if it was set):
_coordinate1 = kCLLocationCoordinate2DInvalid;
_coordinate2 = kCLLocationCoordinate2DInvalid;
And then in method i check if they're valid:
- (void)checkIfValid {
BOOL coordinatesAreValid = (CLLocationCoordinate2DIsValid(_coordinate1) && CLLocationCoordinate2DIsValid(_coordinate2));
NSAssert(coordinatesAreValid, @"You didn't set up coordinates!");
}
Before i call the method, i set these coordinates via this way:
[_myclassinstance setCoordinate1:CLLocationCoordinate2DMake(mapView.region.center.longitude, mapView.region.center.latitude)];
[_myclassinstance setCoordinate2:CLLocationCoordinate2DMake(mapView.region.center.longitude, mapView.region.center.latitude)];
[_myclassinstance checkIfValid];
The problem is that an app claims, the coordinates are wrong. I've printed them, they seem to be ok:
(lldb) p _coordinate1
(CLLocationCoordinate2D) $1 = {
latitude = -122.4612387012154
longitude = 37.72925050874177
}
(lldb) p _coordinate2
(CLLocationCoordinate2D) $2 = {
latitude = -122.3582012987846
longitude = 37.84612098703619
}
However printing checking isn't working, also assert runs:
p (int)CLLocationCoordinate2DIsValid(_coordinate1)
(int) $3 = 0
Does anyone have any idea why is this happening? Any help will be welcomed :)
I don't know much about what CLLocationCoordinate2DIsValid
supposed to give you, but according to the docs:
A coordinate is considered invalid if it meets at least one of the following criteria:
- Its latitude is greater than 90 degrees or less than -90 degrees.
- Its longitude is greater than 180 degrees or less than -180 degrees.
So since your latitude is less than -90 degrees, I guess the method is just doing their job.
Edit: It appears that you just used CLLocationCoordinate2DMake
with wrong parameters. It should be:
[_myclassinstance setCoordinate1:CLLocationCoordinate2DMake(lattitude, mapView.region.center.longitude)];
Swap latitude
and longitude
.
From the documentation:
A coordinate is considered invalid if it meets at least one of the following criteria:
Its latitude is greater than 90 degrees or less than -90 degrees. Its longitude is greater than 180 degrees or less than -180 degrees.
Looks like your latitude is -122 deg. which is outside of the valid range.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With