首页 > 解决方案 > GPS坐标添加角度不正确的米

问题描述

我有这个功能,如果我想以给定角度向现有坐标(纬度/经度)添加以米为单位的距离(x 和 y):

 * Calculates a new GPS coordinate from given coordinates and a given movement distances in meters
 *
 * @param lat0  the latitude to move from
 * @param long0 the longitude to move from
 * @param dx    the distance to move on the x axis in meters. Use positive values to move to the east(right) and negative values to move to the west(left)
 * @param dy    the distance to move on the y axis in meters. Use positive values to move to the north (up) and negative values to move to the south(down)
 * @return a new double array containing the target coordinates: [latitude, longitude]
 */
public double[] calculateCoordinatesAfterMove(double lat0, double long0, double dx, double dy) {
    double lat = lat0 + (180 / Math.PI) * (dy / 6378137);
    double lon = long0 + (180 / Math.PI) * (dx / 6378137) / Math.cos(Math.PI / 180.0 * lat0);
    return new double[]{lat, lon};
}

public double[] calculateCoodinatesAfterMove(Waypoint w, double dx, double dy, double angle) {
    return calculateCoordinatesAfterMove(w, dx * Math.cos(angle * Math.PI / 180), dy * Math.sin(angle * Math.PI / 180));
}

public double[] calculateCoordinatesAfterMove(double lat0, double long0, double dx, double dy, double angle) {
    return calculateCoordinatesAfterMove(lat0, long0, dx * Math.cos(angle * Math.PI / 180), dy * Math.sin(angle * Math.PI / 180));
}

我还有一个计算两个坐标之间方位角的函数,我检查了这个函数是否正确。

问题是上面的函数没有创建具有指定角度的航点。
这是一个示例调用,我指定角度为 64:

double[] resultMove = coordinateCalculator.calculateCoordinatesAfterMove(48.993268432102354, 8.395133104531464, 10, 5, 64);
        System.out.println(resultMove[0] + ", "  +resultMove[1]);
        System.out.println("Calculated angle: " + coordinateCalculator.calculateAngleBetweenWaypoints(
                48.993268432102354, 8.395133104531464, resultMove[0], resultMove[1]
        ));

这给了我一个计算出的航点:

48.993308802123806, 8.395193120821242

以及计算出的角度与 44.2XXX 度的起点之间的角度是正确的(在此处检查:https: //www.movable-type.co.uk/scripts/latlong.html

纬度和经度始终如示例中所示传递,应该是弧度。如果这种表示是度数,请纠正我:)

有人可以帮我为什么我的函数没有返回所需角度的航点吗?

标签: javagps

解决方案


推荐阅读