【问题标题】:Defining a threshold for Distance between two GEO Locations?定义两个 GEO 位置之间的距离阈值?
【发布时间】:2013-05-23 00:58:18
【问题描述】:

我在我的应用程序中获得了两个 GEO 位置,我必须计算它们之间的距离,在距离计算之后,我必须将该结果与定义的阈值(在我的情况下为 50 meters)进行比较,我将如何定义该阈值在浮动。此外,目前我的 android fone 位于同一位置,但我总是在间隔超过 50 米后确定我的 2 个两个地理位置之间的计算距离。这怎么可能?我将 50 米的阈值视为:

private static final float DISTANCE_CHANGE_METERS = 50.0f; //50 meters

我正在通过在 StackOverflow 上找到的以下公式计算距离:

public static float distFrom(double lat1, double lng1, double lat2, double lng2) {

    double earthRadius = 3958.75;
    double dLat = Math.toRadians(lat2 - lat1);
    double dLng = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) * Math.sin(dLng / 2) * Math.sin(dLng / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double dist = earthRadius * c;

    int meterConversion = 1609;

    return new Float(dist * meterConversion).floatValue();
}

请在这方面帮助我。谢谢!

【问题讨论】:

    标签: android geolocation location distance


    【解决方案1】:

    Currently my android phone is at the same location, but I always get the calculated distance between my 2 two geolocations determined after an interval to be more than 50 meters. How is that possible?

    这实际上取决于您如何将纬度和经度传递给distFrom 函数。只是提醒您,有一种更简单的方法可以计算距离。
    您可以使用 android API 中的 distanceTo() 函数使用 Location 来计算两个地方之间的距离,如下所示:

    Location locationA = new Location("point A");
    locationA.setLatitude(latA); // co-ordinates in double
    locationA.setLongitude(lngA);
    
    Location locationB = new Location("point B");
    locationB.setLatitude(latB);
    locationB.setLongitude(lngB);
    
    float distance = locationA.distanceTo(locationB);
    

    如果在使用此功能后您的距离也大于 50 米,那么您提供的坐标就不是那么准确。它非常好,因为它很难以低于 50 米的精度获得精度。如果您将互联网与 GPS 一起使用,那将是最准确的。如果您看到here,即使您使用ACCURACY_HIGH 作为选择Location Provider 的标准,它也提供了小于100 米的精度。它可以精确到 100、70 甚至 50 米。因此,即使是最准确的选项也不能保证提供极高的准确性。如果您使用 GPS/网络提供商获取位置,那么您的情况很有可能。使用 `Network Provider1 获取位置也不是那么准确,因为它可以在不同的场合捕捉到 2 个网络塔的信号,这些信号在物理上可能相距甚远。

    希望它在某种程度上有所帮助并澄清这一点。它的问题是您的位置提供程序的准确性。

    【讨论】:

      【解决方案2】:

      你能做到吗:

      if (distFrom(lat1,lng1,lat2,lng2) > DISTANCE_CHANGE_METERS)
      {
          //greater than threshhold
      }
      

      【讨论】:

      • 我正在这样做......但我很困惑,这就是为什么我的距离总是大于 50 米,因为我从来没有从我之前所在的位置移动一英寸......??? ?
      • 您能提供一组您正在使用的坐标吗?
      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 2011-03-16
      • 2020-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多