0

私はこの質問がたくさん聞かれていることを知っていますが、まだ満足のいくものではありません。AndroidデバイスのGPSを使用して速度を計算しようとしています。多くの人は、LocationオブジェクトのgetSpeed()関数を使用するだけだと言って返信しているようです。私が理解していることから、g​​etSpeed()は、GPS受信機チップに速度センサーが組み込まれている特定のデバイスでのみ機能します。これに関係なくアプリケーションを動作させたいので、次の半正矢関数を使用しています。

private double CalculateHaversineMI(double lat1, double long1, double lat2,double long2) {
    double dlong = (long2 - long1) * (Math.PI / 180.0f);
    double dlat = (lat2 - lat1) * (Math.PI / 180.0f);
    double a = Math.pow(Math.sin(dlat / 2.0), 2)
        + Math.cos(lat1 * (Math.PI / 180.0f))
        * Math.cos(lat2 * (Math.PI / 180.0f))
        * Math.pow(Math.sin(dlong / 2.0), 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = 3956 * c;

    return d;
}

今私がやろうとしているのは、これから速度を計算する方法を理解することです。誰か助けてくれませんか?

4

2 に答える 2

3

What I can see is that your function returns correct path distance between 2 points on a sphere - it is d. But, this formula is needed only if you have 2 points on a sphere that are not close to each other (means central angle of their separation is not small, central angle of 1 degree corresponds to distance of 111 km approx, just to get feeling). If they are close to each other (which is the case for people moving and slow speed vehicles), then you do not need this formula. You can simply and very accurately approximate arc on the sphere with the straight line, and then calculation becomes trivial.

  • Sample GPS position at regular time periods. Calculate distance from the last position obtained. For that purpose you may use distanceTo() function from android.location.Location.
  • Calculate speed by dividing distance with time elapsed between 2 measurements.
  • Average calculated speeds for more accurate results, but ensure that you do not lose sensitivity to speed changes. So, you would need some trade-off on number of samples averaged.
于 2011-05-17T06:08:44.070 に答える
0

それは距離を計算します。覚えているかもしれませんが、速度=距離/時間なので、線のどこかで時間と位置をキャプチャする必要があります。

別の注意点として、あなたが使用している公式は、あなたがやろうとしていることに対する方法OTTです。通過するパスが地球の円周よりもはるかに小さいという事実に基づいて、いくつかの近似を行う方がよいでしょう。そうすれば、もっと簡単な式にたどり着くことができます。

于 2011-05-17T06:18:00.643 に答える