我玩弄鈦,和現在用這個公式來計算距離這個地理定位計算有多準確?
toRad = (x) ->
x * Math.PI/180
toDeg = (x) ->
x * 180/Math.PI
startingLat = hsc.models.startingPosition.latitude
startingLon = hsc.models.startingPosition.longitude
currentLat = e.coords.latitude
currentLon = e.coords.longitude
R = 6371
dLat = toRad(currentLat - startingLat)
dLon = toRad(currentLon - startingLon)
a = Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(toRad(startingLat)) * Math.cos(toRad(currentLat)) *
Math.sin (dLon/2) * Math.sin(dLon/2)
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
d = R * c;
hsc.models.positionUpdateCallback (d * 1093.6133) if hsc.models.positionUpdateCallback
console.log "distance is [#{d}]km"
我測試如下。
從點A開始。
啓用跟蹤。
在B點結束。
記錄值。 清除。
啓用跟蹤。
回到A點
記錄值
在6次我已經122和135之間有值This tool告訴我的距離是124.9碼。
而這可能是8鐵和7鐵的區別,所以這是重要的人!
編輯:我想知道如果我得到的初始位置的方式是有缺陷的。
以下是我在用戶點擊開始時如何開始跟蹤。
hsc.models.startTracking = (onUpdate) ->
return if hsc.models.isTracking
Ti.App.idleTimerDisabled = true;
Ti.Geolocation.setFrequency 100
Titanium.Geolocation.setAccuracy = Titanium.Geolocation.ACCURACY_BEST;
Titanium.Geolocation.setDistanceFilter 0
hsc.models.positionUpdateCallback = onUpdate
hsc.models.isTracking = true;
Ti.Geolocation.addEventListener 'location', hsc.models.locationUpdate
這裏是我如何完成,當用戶點擊結束。
if hsc.models.isTracking is true
Ti.App.idleTimerDisabled = false;
hsc.models.isTracking = false
hsc.models.startingPosition = null
Ti.Geolocation.setFrequency 500000
Titanium.Geolocation.setDistanceFilter 10
Ti.Geolocation.removeEventListener 'location', hsc.models.locationUpdate
在
locationUpdate
我做
if not hsc.models.startingPosition
hsc.models.startingPosition = e.coords
else
#do the calculation
所以基本上我剛開始接收更新,當我拿到第一個,我設置的初始位置。我想知道是否需要執行初始的getCurrentPosition
,然後註冊位置回調處理程序。這可能會處理第一次更新略微延遲一點的情況。
更多信息
所以我實現,嘗試了新的戰略 - 讓起始位置,然後開始監聽變化的事件(不移動,而第1步中出現),我仍然可以看到相當大的差異。我從A - > B去了134碼,然後從B - > A拿到了117碼。我從門口跑到託兒所去取得後代,並且註冊了2220碼,從我停着的車回到我的門上,得到了2268碼。
更多的是,坐在同一個地方,它註冊了位置的變化,最多20碼!
我必須在這裏做得不對.....
它是如何「漂移」這麼多。就像我說的,坐在我的椅子上,長達25碼? – hvgotcodes 2012-08-01 23:29:54
由於電離層和對流層中的不斷變化會干擾GPS信號。看到這個鏈接。 http://goo.gl/iSC8Z – 2012-08-02 00:19:00
所以你說的是,手機無法準確讀取精確到兩碼的讀數。現在使用谷歌地圖數據怎麼樣?選擇2個位置並計算它們之間的距離有多準確? – hvgotcodes 2012-08-02 00:31:50