CLLocation distanceFromLocation: returns zero on iOS 9. Is this an error?

Code to reproduce the problem:

-(void)testDistance { NSLog(@"Test distance..."); CLLocation *location1 = [[CLLocation alloc] initWithLatitude:137.02954600000001 longitude:50.543728999999999]; CLLocation *location2 = [[CLLocation alloc] initWithLatitude:55.79676300 longitude:49.10834400]; CLLocationDistance distance = [location1 distanceFromLocation:location2]; NSLog(@"Distance: %lf", distance); } 

iOS 8.4 output:

Distance: 9021699.415204

iOS 9.1 output:

Distance: 0.000000

location1 and location2 not zero.

I was looking for SO for a similar question, but could not find it. Looks like an iOS 9 bug for me. Do you agree? Do you get similar results? I wanted to send an Apple bug report, but first I want to confirm.

I ran the code on simulators (both iOS 8.4 and iOS 9.1). The system language was installed in Russian, the region was installed in Russia.

UPDATE: lat and lon were mixed. Latitude should be in the range [-90, 90]. In previous versions of iOS, it still produced some result. In iOS 9, they returned it 0 . I do not think that this is a good return value for such a case, because it is a perfectly acceptable value. I think they should return some error code (e.g. for nil , returning -1 ). At least that should be mentioned in the docs. I am going to file a bug report soon.

+5
source share
1 answer

Check the latitude value of location1. I assume that there is some mismatch with the latitude range (-90, 90).

+2
source

Source: https://habr.com/ru/post/1234527/


All Articles