【问题标题】:Android GPS accuracy in calculating distance issuesAndroid GPS 精度计算距离问题
【发布时间】:2014-02-25 09:44:13
【问题描述】:

我认为这个问题众所周知。

那么我的问题是什么?

我正在编写一个应用程序,它使用 GPS 提供程序来查找用户的位置并计算从用户到终点的距离。这可以正常工作。但是出现了问题:

问题详情:

如果您使用我的应用程序在城市中转转,它会为您提供一些距离数字,但是......距离正在改变。无论我是否朝着目的地移动,距离要么变高要么变低(计算的距离值是从高到低“跳跃”,反之亦然)之前的距离数字,但从逻辑上讲它应该越来越低.我相信这是因为 GPS 信号有时会丢失或微弱,无法正确计算距离。

我需要什么帮助?

我想知道有没有办法过滤从 GPS 接收到的坐标,这样我就可以获得更准确的距离数字,所以当我向终点移动时,距离计算正确(尽可能不必是 100%正确),而不是像疯了似的上下秤。

如何获取坐标并计算距离:

public void onLocationChanged(Location location) 
{
    txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
    clat = location.getLatitude();
    clong = location.getLongitude();

    Location location1 = new Location("Start");
    location1.setLatitude(clat);
    location1.setLongitude(clong);

    Location locationB = new Location("Finish");

    locationB.setLatitude(endLatitude); //endpoint coordinates
    locationB.setLongitude(endLongitude);

    distance = location1.distanceTo(locationB); //calculate the distance

    TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
    TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");

    CurLat = location.getLatitude();
    CurLong = location.getLongitude();  

【问题讨论】:

  • 你知道location对象有accuracy属性吧?
  • 好吧,这是真的,但我不知道如何实现它,你能告诉我吗?

标签: android localization gps


【解决方案1】:

可以通过保存最后的(例如 10 个)位置对象并根据这些对象进行计算来进一步改进以下答案。例如,如果最后 10 个位置表明用户正以 1m/s 的速度向目标移动,那么建议跳跃 5 米的新位置很可能不准确,应该被忽略。

要过滤一些已更新的 GPS,您可以简单地执行以下操作(3 表示位置相对于您的实际位置应该有多准确,并且可以进行调整):

    public void onLocationChanged(Location location) 
    {
        if (location.hasAccuracy() && location.getAccuracy() < 3) {
            txtLat = (TextView) findViewById(R.id.currentCoordinatesView);
            clat = location.getLatitude();
            clong = location.getLongitude();

            Location location1 = new Location("Start");
            location1.setLatitude(clat);
            location1.setLongitude(clong);

            Location locationB = new Location("Finish");

            locationB.setLatitude(endLatitude); //endpoint coordinates
            locationB.setLongitude(endLongitude);

            distance = location1.distanceTo(locationB); //calculate the distance

            TextView TextDistance = (TextView)findViewById(R.id.TextDistance);
            TextDistance.setText(new DecimalFormat("##,###,###.##").format(distance)+" m");

            CurLat = location.getLatitude();
            CurLong = location.getLongitude(); 
        }
    }

这里是准确度度量的定义,来自:Location getAccuracy()

获取此位置的估计精度,以米为单位。 我们将准确度定义为 68% 置信度的半径。换句话说,如果你以这个位置的经纬度为中心画一个圆,半径等于精度,那么有 68% 的概率是真正的位置在这个圆内。

在统计方面,假设位置误差是随机的,服从正态分布,因此 68% 的置信度圆代表一个标准差。请注意,在实践中,位置误差并不总是遵循如此简单的分布。

此精度估计仅与水平精度有关,如果包含在此位置中,则不指示方位、速度或高度的精度。

如果此位置没有准确度,则返回 0.0。 LocationManager 生成的所有位置都包含精度。

【讨论】:

  • 您好,谢谢您的回答,但您能否向我解释一下为什么 location.hasAccuracy && location.getAccuracy() 必须小于 3.0?你能告诉我如何存储和计算你在回答中建议的位置吗
  • 根据你的建议 OnLocation() 永远不会被调用:/
  • 3.0 只是一个示例,如前所述,它可能会进行调整。我没有一个实际的例子,但它只是将有效/过滤的位置对象存储在一个列表中。然后在每个位置更改上迭代列表并计算平均速度 (location.getSpeed()) 或其他可以帮助您确定新位置是​​否有效的东西。但首先尝试准确性,如果证明有足够的改进,则无需使事情复杂化。
  • 你确定你真的得到了 GPS 值吗?可能是基于网络的位置..也可能解释精度差。
  • 为了绝对确定您实际使用的是 GPS,您可以使用我的实现仅在 GPS 首次修复时接受位置更改,请参阅:stackoverflow.com/questions/19365035/…
猜你喜欢
  • 1970-01-01
  • 2012-01-19
  • 2013-08-14
  • 2017-07-25
  • 1970-01-01
  • 2017-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多