我一直在努力弄清楚为什么distanceFromLocation没有为两个CLLocations提供正确的距离。计算结果是大于实际距离的数字,但这两个位置似乎是有效位置。
首先,这是两个地点:
位置1:< +44.56697840, -69.55759810> +/- 0.00m(速度-1.00 mps /航向-1.00)@ 2010-12-13 21:12:03 -0500
地点2: < +44.31400400,-69.79157000> +/- 0.00m (速度-1.00 mps /当然-1.00)@ 2010-12-13 21:12:03 -0500
这里是声明Location1和Location2的代码。我已经确认这些是正确的值,但我仍然无法弄清楚
CLLocation *newLocation = [[CLLocation alloc]
initWithLatitude:[latitude doubleValue]
longitude:[longitude doubleValue]];
// CURRENT LOCATION (OR SEARCHED LOCATION)
double dLat = 0;
int tmpDistance = 0;
id returnId = nil;
id tmp = [featuredResults objectAtIndex:i];
CLLocation *newLocation2 = [[CLLocation alloc]
initWithLatitude:[[tmp valueForKey:@"lat"] doubleValue]
longitude:[[tmp valueForKey:@"lng"] doubleValue]];
dLat = [newLocation distanceFromLocation:newLocation2];
我为dLat获得的值是330707027,这是错误的。有谁知道我可能会出错?谢谢!
答案 0 :(得分:0)
这个基于问题中的测试代码给出了大约33,669米:
CLLocation *newLocation = [[CLLocation alloc]
initWithLatitude:44.56697840 longitude:-69.55759810];
CLLocation *newLocation2 = [[CLLocation alloc]
initWithLatitude:44.31400400 longitude:-69.79157000];
double dLat = [newLocation distanceFromLocation:newLocation2];
NSLog(@"distance = %f meters", dLat);
[newLocation release];
[newLocation2 release];
输出:
距离= 33669.002406米
也许您正在使用%f
以外的其他内容记录dLat?