Android 从 GPS 坐标计算平均速度的最佳实践
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2796157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Best practice to calculate the average speed from GPS coordinates
提问by RoflcoptrException
I have here a device which can give me GPS coordinates. The time interval I can define. I want to use it to calculate the average speed during driving or travelling by car. Actually I used a orthodrome formula to calculate the distance between two points and then divided it by the given time interval. By the implementation I followed this term. Unfortunately I could only find a German link, but I think the formula should be understandable in any language ;)
我这里有一个可以给我 GPS 坐标的设备。我可以定义的时间间隔。我想用它来计算开车或开车旅行时的平均速度。实际上我使用了一个orthodrome公式来计算两点之间的距离,然后除以给定的时间间隔。通过实现,我遵循了这个术语。不幸的是,我只能找到德语链接,但我认为该公式应该可以用任何语言理解;)
Unfortunately, using this formula and a time interval of 1 second gives very unprecise results. The speed while walking is between 1 km/h and 20 km/h.
不幸的是,使用这个公式和 1 秒的时间间隔会给出非常不精确的结果。步行时的速度在 1 公里/小时到 20 公里/小时之间。
So I wonder if there is a general reference on how to implement distance calculation between two GPS coordinates (I found something similar on SO) and particulary, which is the best time interval to update the GPS coordinates?
所以我想知道是否有关于如何实现两个 GPS 坐标之间的距离计算的一般参考(我在 SO 上发现了类似的东西),特别是更新 GPS 坐标的最佳时间间隔是什么?
回答by MusiGenesis
I assume that you're testing this by walking at a constant speed (I think ~5 kph is a normal walking speed) while measuring your GPS position once per second.
我假设您通过以恒定速度步行(我认为大约 5 公里/小时是正常步行速度)来测试这一点,同时每秒测量一次 GPS 位置。
The variation that you're seeing in instantaneous speed (the distance between each measured point divided by 1 second) is either due to random variation in the measured GPS position or else you aren't taking your measurements exactlyone second apart (or it could be both of these things).
您看到的瞬时速度变化(每个测量点之间的距离除以 1 秒)要么是由于测量的 GPS 位置的随机变化造成的,要么是您的测量间隔不完全一秒(或者可能是这两件事)。
I'm going to assume your measurements arebeing taken precisely one second apart. Hand-held GPS devices are muchless accurate than advertised. While it's often claimed that the devices are accurate to within 10 ft. of the true position, this simply isn't so.
我会假设你的测量是采取精确相隔一秒。手持式 GPS 设备远不如宣传的那样准确。虽然人们经常声称这些设备可以精确到真实位置的 10 英尺以内,但事实并非如此。
The best way to measure and report the accuracy of a GPS device is to leave it in a place where it can see the satellites and not be rained on, and record a few day's worth of data. You can then use Google Maps to plot the points - I've done this around my house and around the office, which is a good way to give you a sense of scale.
测量和报告 GPS 设备精度的最佳方法是将其放置在可以看到卫星且不会被雨淋的地方,并记录几天的数据。然后你可以使用谷歌地图来绘制这些点——我已经在我家和办公室周围做了这个,这是给你一种比例感的好方法。
Obviously, if the devices were perfectly accurate, you would see all your measured points in one spot. Or, if the 10 ft. accuracy thing were true, you would see all the points in a little cluster inside a 20 ft. diameter circle.
显然,如果设备非常准确,您将在一个点上看到所有测量点。或者,如果 10 英尺的精度是真的,你会在一个 20 英尺直径的圆内看到一个小簇中的所有点。
What you see instead (with every GPS-enabled device I've ever tested) is a combination of relatively small positional scattering (on the order of a few tens of feet) occurring on a scale of a few seconds, and a longer-term "random walk" of the average position which might move 200 or 300 ft. in the course of a day or two. When plotted over your own house, for example, it might look like your PDA wandered over to the neighbor's house, then across the street, then down the street two houses, back towards you etc., all while jittering around 5 or 10 feet here or there like it drank too much coffee.
相反,您看到的(对于我测试过的每个支持 GPS 的设备)是发生在几秒钟的范围内的相对较小的位置散射(大约几十英尺)和更长期的组合平均位置的“随机游走”可能在一两天内移动 200 或 300 英尺。例如,当绘制在您自己的房子上时,您的 PDA 可能看起来像是徘徊到邻居的房子,然后穿过街道,然后沿着街道走两座房子,回到您身边等等,同时在这里抖动大约 5 或 10 英尺或者那里喜欢喝太多咖啡。
GPS canbe more accurate than this. Surveyors use devices with much more powerful receiver sets (so they get a much more accurate read on the satellite signals), and they leave them in place for days at a time to average successive measurements. Handheld devices have cheap receiver chips and cheap antennas and have to deal with all kinds of signal interference anyway.
GPS可以比这更准确。测量员使用具有更强大接收器的设备(因此他们可以更准确地读取卫星信号),并且他们将它们一次放置数天以平均连续测量。手持设备拥有廉价的接收器芯片和廉价的天线,无论如何都要应对各种信号干扰。
Your best bet is to do a running average to calculate your instantaneous speed. Instead of dividing the distance between the current point and the previous point by 1 second, take the last 5 distances between points and divide by 5 seconds (or whatever number of seconds you use). It's important not to just take the difference between the current point and the point 5 seconds ago and divide this distance by 5, as that would miss any non-linear movement.
最好的办法是做一个运行平均值来计算你的瞬时速度。不是将当前点和前一点之间的距离除以 1 秒,而是取点之间的最后 5 个距离并除以 5 秒(或您使用的任何秒数)。重要的是,不要仅仅将当前点与 5 秒前的点之间的差值除以 5,否则会错过任何非线性运动。
Update:I noticed in a comment that you're using an Android device. Do you know if it has a built-in GPS receiver? Many (most?) Android devices don't, which means their GPS is not the triangulate-on-the-satellites version of GPS, but the guess-where-I-am-based-on-the-signal-from-the-cell-towers version. This is muchless accurate positionally, as I'm sure you could tell from the snarkiness of my description. :)
更新:我在评论中注意到您使用的是 Android 设备。你知道它是否有内置的 GPS 接收器吗?许多(大多数?)Android 设备没有,这意味着它们的 GPS 不是 GPS 的三角测量版本,而是基于来自信号的猜测我在哪里-细胞塔版本。这是很多不太精确位置上,因为我敢肯定,你可以从我描述的snarkiness告诉。:)
回答by Marcelo Cantos
GPS systems can yield instantaneous velocity directly, without interpolating positions. I read somewhere that the velocity reading is actually more accurate than the position reading. What device/system/OS are you using?
GPS 系统可以直接产生瞬时速度,无需插入位置。我在某处读到速度读数实际上比位置读数更准确。您使用的是什么设备/系统/操作系统?
On Android, try the android.location.Location.getSpeed()
method (along with hasSpeed()
) in your LocationListener
implementation.
在 Android 上,尝试实现中的android.location.Location.getSpeed()
方法(以及hasSpeed()
)LocationListener
。
回答by Urban Holmdahl
Search on google for GPS SPEED ACCURACY, and you will find reports stating that speed calculated out of position-vs-time is ten times worse than just using the speed parameter coming right out from the GPS receiver. The speed parameter is not depending on position accuracy, but is calculated out of doppler (speed/frequency difference) from the satellite signals.
在 google 上搜索 GPS SPEED ACCURACY,您会发现报告指出,根据位置与时间计算出的速度比仅使用来自 GPS 接收器的速度参数差十倍。速度参数不取决于位置精度,而是根据卫星信号的多普勒(速度/频率差)计算得出。
Good luck
祝你好运