CLLocation距离计算是否有状态?我该如何解决?

时间:2019-05-24 18:37:02

标签: ios

我发现在使用[CLLocation distanceFromLocation:]计算零距离之后,后续的非零距离计算与零距离调用之前不同。是真的,如果是这样,是否有解决方法来获得一致的结果?

该程序当前正在使用Xcode 10.1在“ iPad Air-12.1”模拟器上运行。

NSLog(@"loc1 =%.20f %.20f", loc1.coordinate.longitude, loc1.coordinate.latitude);
NSLog(@"loc2 =%.20f %.20f", loc2.coordinate.longitude, loc2.coordinate.latitude);
NSLog(@"result1 = %.20f", [loc1 distanceFromLocation:loc2]);
NSLog(@"loc1 =%.20f %.20f", loc1.coordinate.longitude, loc1.coordinate.latitude);
NSLog(@"loc2 =%.20f %.20f", loc2.coordinate.longitude, loc2.coordinate.latitude);
NSLog(@"garbage = %.20f", [loc1 distanceFromLocation:loc1]);
NSLog(@"loc1 =%.20f %.20f", loc1.coordinate.longitude, loc1.coordinate.latitude);
NSLog(@"loc2 =%.20f %.20f", loc2.coordinate.longitude, loc2.coordinate.latitude);
NSLog(@"result2 = %.20f", [loc1 distanceFromLocation:loc2]);
NSLog(@"loc1 =%.20f %.20f", loc1.coordinate.longitude, loc1.coordinate.latitude);
NSLog(@"loc2 =%.20f %.20f", loc2.coordinate.longitude, loc2.coordinate.latitude);
return [loc1 distanceFromLocation:loc2] / CGFloat(US_NAUTICAL_MILE_TO_METRE);```

我不希望在输出中看到result1和result2不同:

2019-05-24 14:12:06.361771-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc1 =-96.25799399999999650390 33.44624999999999914735
2019-05-24 14:12:06.361872-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc2 =-97.03769400000000189266 32.89723099999999789134
2019-05-24 14:12:06.362052-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] result1 = 94849.40430844188085757196
2019-05-24 14:12:06.362263-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc1 =-96.25799399999999650390 33.44624999999999914735
2019-05-24 14:12:06.362375-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc2 =-97.03769400000000189266 32.89723099999999789134
2019-05-24 14:12:06.362599-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] garbage = 0.00000000000000000000
2019-05-24 14:12:06.362776-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc1 =-96.25799399999999650390 33.44624999999999914735
2019-05-24 14:12:06.362899-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc2 =-97.03769400000000189266 32.89723099999999789134
2019-05-24 14:12:06.363118-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] result2 = 94676.80041732524114195257
2019-05-24 14:12:06.363339-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc1 =-96.25799399999999650390 33.44624999999999914735
2019-05-24 14:12:06.363574-0400 ... -[RouteParserRoute distanceInNauticalMilesFrom:to:] loc2 =-97.03769400000000189266 32.89723099999999789134

0 个答案:

没有答案