【发布时间】:2012-01-11 21:16:16
【问题描述】:
我正在尝试执行great circle distance calculation。正如您应该能够收集到的,Location 类具有计算中列出的属性。
- (NSNumber *)greatCircleDistanceFrom:(Location *)other
{
// Unpack all the NSNumbers into doubles so we can manipulate them
double selfCosRadLat = [self.cosRadLat doubleValue];
double otherCosRadLat = [other.cosRadLat doubleValue];
double selfRadLng = [self.radLng doubleValue];
double otherRadLng = [other.radLng doubleValue];
double selfSinRadLat = [self.sinRadLat doubleValue];
double otherSinRadLat = [other.sinRadLat doubleValue];
// Multiplying by 3959 calculates the distance in miles.
double d = acos(selfCosRadLat
* otherCosRadLat
* cos(selfRadLng - otherRadLng)
+ selfSinRadLat
* otherSinRadLat
) * 3959.0;
return [NSNumber numberWithDouble:d];
}
在我运行单元测试的一半时间里,我得到了正确的值。另一半,我得到6218.78265778。
【问题讨论】:
-
可以使用CLLocation内置的distanceFromLocation方法。
-
那使用大圆距离公式吗?
标签: objective-c ios geolocation gps