我正在寻找一种平滑的方法来计算两个GPS点之间的距离,以便我可以得到结果,如:“您需要向上移动x米和向左移动y米 - 这样我就可以使用二维坐标系进行操作,其中我的位置为(0,0),其他位置显示的是相对于我的位置以米为单位的(x,y)距离。”
我的想法是使用haversine公式计算两点之间的距离。(这返回我的斜边)
除此之外,我还计算了这两个点之间的方位角。这是我的alpha。
有了这两个值,我想使用基本三角函数解决我的问题。
所以我尝试计算:
也许我做错了什么,但目前我的结果是无用的。
所以我的问题是:如何计算两个GPS点之间在x和y方向上的距离?
我按以下步骤计算alpha:
我的想法是使用haversine公式计算两点之间的距离。(这返回我的斜边)
除此之外,我还计算了这两个点之间的方位角。这是我的alpha。
有了这两个值,我想使用基本三角函数解决我的问题。
所以我尝试计算:
catheti_1 = sin(alpha) * hypotenuse, catheti_2 = cos(alpha) * hypotenuse
。也许我做错了什么,但目前我的结果是无用的。
所以我的问题是:如何计算两个GPS点之间在x和y方向上的距离?
我按以下步骤计算alpha:
public static double bearingTo(GPSBean point1, GPSBean point2) {
double lat1 = Math.toRadians(point1.latitude);
double lat2 = Math.toRadians(point2.latitude);
double lon1 = Math.toRadians(point1.longitude);
double lon2 = Math.toRadians(point2.longitude);
double deltaLong = lon2 - lon1;
double y = Math.sin(deltaLong) * Math.cos(lat2);
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1)
* Math.cos(lat2) * Math.cos(deltaLong);
double bearing = Math.atan2(y, x);
return (Math.toDegrees(bearing) + 360) % 360;
}
lat2
使用了point2.longitude
。这样不会得到正确答案...... - Floris