私はチタンで遊んでいて、この式を使用して距離を計算しています
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 の間の値が得られ ました。このツールは、距離が 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
initial を実行してから、ロケーション コールバック ハンドラを登録する必要があるのだろうかと思います。これは、最初の更新が少し遅れた場合に少しうまく処理できる可能性があります。
より詳しい情報
そこで、新しい戦略を実装して試してみました。開始位置を取得してから、変化するイベント (ステップ 1 が発生している間は移動しない) をリッスンし始めましたが、それでもかなり大きな不一致が見られます。A→Bで134ヤード、B→Aで117ヤード。私は子供を産むために玄関から保育園まで走り、2220ヤードを記録し、駐車中の車から玄関まで2268ヤードを記録しました。
さらに、同じ場所に座っていると、位置の変化が記録され、20 ヤード上昇します。
私はここで何か間違ったことをしているに違いない.....