写一个GPS记录应用程序〜Android的GPS定位速度不可靠
我发现通过Locations
的getSpeed()
方法,通过LocationManager
报道返回的值是大量不可靠的。我正在使用LocationManager.GPS_PROVIDER
,过滤通过onLocationChanged
提供的位置以获得最佳准确性。即使在一位数的精度水平上,返回的速度通常也很高。当手机处于静止状态时,我们正在谈论高达200 mp/h(是的,我知道它以米/秒记录)。
我在两个不同型号的Android手机上测试相同的代码库,运行两个不同的操作系统版本,并看到相同的问题,所以我期望这是一个代码问题。
我错过了什么?我尝试过在一段时间内平均地点,但无济于事。我是否必须根据行驶距离/时间计算出我自己的速度值?这会令人失望。
正如你所看到的,我没有做什么特别的东西 - 对精度的过滤不大,甚至在此之后双方AverageSpeed
和_bestLocation.getSpeed()
是定期unfeasibly高,即使在定位精度好。
public void onLocationChanged(Location location) {
if (location.getAccuracy() < 25f) {
_recentLocations.add(location);
if (_bestLocation == null || location.getAccuracy() <= _bestLocation.getAccuracy())
_bestLocation = location;
}
if ((_bestLocation != null && _bestLocation.getAccuracy() < 10f && _recentLocations.size() >= 10)
|| _recentLocations.size() >= 25)
{
int Count = 0;
float TotalSpeed = 0f;
float AverageSpeed = 0f;
for (int i = 0; i<_recentLocations.size(); i++) {
if (_recentLocations.get(i).hasSpeed()) {
Count++;
TotalSpeed += _recentLocations.get(i).getSpeed();
}
}
if (Count > 0)
AverageSpeed = TotalSpeed/Count;
}
}
您在不同的地方*尝试这个*呢?在某些地方,无论如何你都无法获得GPS定位。 – Piskvor 2012-07-27 10:26:27
我应该指定,我得到非常可以接受的精确修正 - 通常是5 - 10米。地方是尽可能变化 - 从办公室到客户网站和家庭等 – 2012-07-27 10:30:34
@DanWray海,你有没有解决这个问题,现在我正在努力相同,你能帮助我吗? – 2014-08-04 09:35:16