获得距离的更好方法是什么?

时间:2016-04-20 14:00:27

标签: android time

我目前正在编写一个程序,试图通过GPS测量一个人行走的速度。

   if (OldLocation != null) {
        OldLocation = NewLocation;
        NewLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    } else {
        OldLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
        try {Thread.sleep(mInterval);} catch (InterruptedException ex) {
            Thread.currentThread().interrupt();
        }
        NewLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    }
    float distance = OldLocation.distanceTo(NewLocation);
    float speed = distance / mInterval;

在这里,我目前正在使用Thread.sleep'交错',或者在获取OldLocation后延迟获取NewLocation。

但是,我正在使用另一个带有mInterval的系统:

Runnable mStatusChecker = new Runnable() {
    @Override
    public void run() {
        mHandler.postDelayed(mStatusChecker,mInterval);
    }
};

...延迟第一个序列。我不确定这是否真的可以在实践中发挥作用。 任何人都可以在这看到错误,或者更简单的方式来解决它?

谢谢!

0 个答案:

没有答案
相关问题