什么是计算行驶距离过一段时间的最佳方法是什么? [英] What is the best way to calculate distance travelled over a period of time?

查看:329
本文介绍了什么是计算行驶距离过一段时间的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图计算出经过一段时间,为Android平台的应用程序的距离。
什么是做到这一点?
的最佳途径 目前,我实现LocationListener的接口。
我重写方法onLocationChanged

I am trying to calculate the distance elapsed over a period of time in an app for the Android platform.
What is the best way to do this?
At the moment, I am implementing LocationListener interface.
I am overriding the method onLocationChanged

我目前做这样的事情:

public void onLocationChanged(Location location) {
        Log.d("onLocationChanged", "onLocationChanged");


        old_location.set(new_location);
        new_location.set(location);
        totalDistanceElapsed += new_location.distanceTo(old_location);

}
所以我加入从原来的位置点的距离永远时间onLocationChanged被称为新的定位点。 它是否正确? 我需要做什么吗? 这会不会是准确的?如果没有,我怎样才能使它更准确呢?谢谢

}
So I am adding the distance from the old location point to the new location point ever time "onLocationChanged" is called. Is this correct? Do I need to do anything else? Will this be accurate? If not, how can I make it more accurate? thanks

推荐答案

在琐碎的方法来确定行驶距离随着时间的推移将获得修复每一秒,并读取并记录报告对每个固定的速度(米每秒) 。那么你的行驶距离是所有的速度随着时间流逝的时间的总和。

The trivial way to determine distance travelled over time would be to obtain fixes every second, and read and record the speed reported for each fix (in meters per second). Then your distance travelled is the sum of all the speeds over the period of time elapsed.

如果你想避免计数抖动的运动(即,如果该修补程序是徘徊缓慢,因为GPS定位不准确的,但该设备实际上是固定的),你可以设置一个速度阈,如通过忽略速度低于一定的水平,或如果航向修复之间迅速改变。这些阈值可能会取决于所使用的GPS设备,有的设备都有这样的建于已的事(也就是说,如果速度过低,他们0申报米/秒)。

If you want to avoid counting "jitter" as movement (i.e. if the fixes are wandering about slowly because of GPS fix inaccuracies, but the device is actually stationary) you can set a velocity threshold, e.g. by ignoring speeds below a certain level, or if the heading is changing rapidly between fixes. These thresholds will probably depend on the GPS device used, and some devices have this kind of thing built in already (i.e. if the speed is too low they report 0 m/s).

它确实然而取决于设备。对于examply,我的早期型号的三星Galaxy I9000即便是在晴朗的天空条件下,在约半每秒一米徜徉在一个20米半径区域,所以如果它位于固定在一个领域十分钟以上的算法将报告为已经走过3亿英镑。

It really does depend on the device, however. For examply, my early model Samsung Galaxy I9000 wanders about in a 20 meter radius area even in clear sky conditions at about half a meter per second, so if it sits stationary in a field for ten minutes the above algorithm would report it as having travelled 300m.

这篇关于什么是计算行驶距离过一段时间的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆