2

我已将公式转换为此处提供的 Java 。但是准确性是个问题。我们正在使用 GPS 坐标。

我们使用 iPhone 提供的 GPS 定位,精度高达小数点后 10 位。

/*
 * Latitude and Longitude are in Degree
 * Unit Of Measure : 1 = Feet,2 = Kilometer,3 = Miles
 */
//TODO 3 Change Unit of Measure and DISTANCE_IN_FEET constants to Enum
public static Double calculateDistance(double latitudeA,double longitudeA,double latitudeB,double longitudeB,short unitOfMeasure){

    Double distance;

    distance = DISTANCE_IN_FEET * 
               Math.acos(       

                               Math.cos(Math.toRadians(latitudeA)) * Math.cos(Math.toRadians(latitudeB)) 
                           *
                               Math.cos(Math.toRadians(longitudeB) - Math.toRadians(longitudeA))
                           +
                               Math.sin(Math.toRadians(latitudeA))
                           *
                               Math.sin(Math.toRadians(latitudeB))

                       );

    return distance;

}

仅供参考:公共静态最终 int DISTANCE_IN_FEET = 20924640;

然后我使用 Math.round(distance); 转换为长。

对于实际的 25 英尺,我得到 7 英尺的输出。

4

2 回答 2

17

你需要haversine公式

这是我的java实现:

/**
 * Calculates the distance in km between two lat/long points
 * using the haversine formula
 */
public static double haversine(
        double lat1, double lng1, double lat2, double lng2) {
    int r = 6371; // average radius of the earth in km
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = 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(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = r * c;
    return d;
}
于 2013-09-18T01:38:04.017 回答
3

根据Wikipedia的说法,10 英尺接近正常 GPS 精度的极限。(假设您获得了良好的 GPS 信号。) http://gis.stackexchange.com的这篇文章提供了更详细的数字。它基本上说 3 米的水平分辨率是您使用普通 GPS 接收器可能获得的最佳分辨率。

因此,如果您比较两个不同(普通)接收器提供的位置,每个接收器具有最佳情况(3 米/10 英尺)分辨率,您仍然无法可靠地判断一个接收器是否在另一个接收器 10 英尺范围内。


(请注意,您的 10 位“精度”可能是虚幻的。真正的问题是位置的准确性;即误差线有多大……在两个不同的设备上。)


那么在那种情况下,我还有什么其他选择?

链接的文章提到了WAAS和载波相位 GPS (CPGPS)。另一种选择是WPS

于 2013-09-18T00:27:43.293 回答