2010-10-02 147 views
1

在我的應用程序中,當用戶撥打或接聽電話時,我正在收集經度和緯度,我正在用NTSC時間延遲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:起點]

但仍然沒有得到其他結果,在一個論壇上,我讀到在兩個緯度和經度上會有1mile的下降。 那麼有沒有解決方案?

回答

0

地球不是一個完美的球體,所以做簡單的三角學會給你帶來很大的誤差。我相信問題在於它實際上在兩極相當扁平,並且在中間有點膨脹(當我們年齡增長時,很多人都會遇到問題......)

我見過的典型模型用於對此的帳戶是WSG-84。有可能你的平臺已經有了一個庫來處理這個問題。

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]; 
相關問題