使用纬度和频率计算到位置之间的距离经度

时间:2010-10-02 13:32:55

标签: iphone distance

在我的应用程序中,当用户拨打电话或接听电话时,我正在收集纬度和经度我正在使用NSTimer调用一个功能,延迟时间为15秒,我再次收集纬度和经度。

问题在于,当我计算它们之间的距离时,即使我不动,它也会给出最小距离0.87英里或1英里 我使用以下公式

double    distance = (sin(gpslatitudeOld/57.2958) * sin(gpslatitudeNew/57.2958)) + (cos(gpslatitudeOld/57.2958) * cos(gpslatitudeNew/57.2958) * cos(gpslongitudeNew/57.2958 - gpslongitudeOld/57.2958));

来自网站 (http://www.meridianworlddata.com/Distance-Calculation.asp)

我也用过

[newLocation getDistanceFrom:startingPoint]

但仍然没有得到其他结果,在一个论坛中,我读到在两个纬度和经度上将有1英里的上升。 所以有什么解决办法吗?

3 个答案:

答案 0 :(得分:3)

CLLocation *location1 = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];
CLLocation *location2 = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];
NSLog(@"Distance i meters: %f", [location1 distanceFromLocation:location2]);
[location1 release];
[location2 release];

答案 1 :(得分:1)

尝试航空处方网站。 http://williams.best.vwh.net/avform.htm

在计算大距离时,有一些公式可以补偿地球的圆度。

答案 2 :(得分:0)

地球不是一个完美的球体,所以做简单的三角法会给你带来很大的误差。我相信问题是它在两极实际上是相当平坦的,并且在中间有点凸起(我们很多人在我们年龄的时候得到了这个问题......)

我见过的典型模型是WSG-84。您的平台可能已经有了一个库来处理这个问题。

相关问题