我玩弄钛,和现在用这个公式来计算距离这个地理定位计算有多准确?
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