Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CLLocation distanceFromLocation: returns zero on iOS 9. Is it a bug?

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 are not nil.

I searched SO for a similar question but couldn't find one. Looks like an iOS 9 bug to me. Do you agree? Do you get similar results? I wanted to send a bug report to Apple but I wanted to confirm first.

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

UPDATE: lat and lon turned out to be mixed. Latitude should lie in range [-90, 90]. In previous versions of iOS it still produced some result. In iOS 9 they made it return 0. I don't think that this is a good return value for such case, because it is a perfectly valid value. I think that they should return some error code instead (like they do for nil, returning -1). At least, it has to be mentioned in the docs. I'm intending to file a bug report in the nearest future.

like image 245
FreeNickname Avatar asked Oct 26 '15 12:10

FreeNickname


1 Answers

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

like image 141
dasCS Avatar answered Nov 18 '22 23:11

dasCS