1

嗨,我目前正在尝试从 2 个经度/纬度点(双向)计算一个经度/纬度点和距离,我目前已经这样做了:

    double EARTH_RADIUS = 6378137.0;

    double longitude1 = 4.062787;
    double latitude1 = 49.243828;
    double x1 = EARTH_RADIUS * (Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(longitude1)));
    double y1 = EARTH_RADIUS *(Math.cos(Math.toRadians(latitude1)) * Math.sin(Math.toRadians(longitude1)));

    double longitude2 = 4.062023;
    double latitude2 = 49.243851;
    double x2 = EARTH_RADIUS * (Math.cos(Math.toRadians(latitude2)) * Math.cos(Math.toRadians(longitude2)));
    double y2 = EARTH_RADIUS *(Math.cos(Math.toRadians(latitude2)) * Math.sin(Math.toRadians(longitude2)));

    System.out.println(x1 + " " + y1);
    System.out.println(x2 + " " + y2);

    double[][] positions = new double[][] { { x1, y1 }, { x2, y2 } };
    double[] distances = new double[] { 10.0, 10.0};

    NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
    Optimum optimum = solver.solve();

    double[] centroid = optimum.getPoint().toArray();
    System.out.println(Arrays.toString(centroid));

我正在使用这个库https://github.com/lemmingapex/trilateration来确定我的观点。

将经度和纬度点转换为笛卡尔计划并使用库来获取一个点,给我这个输出:

[INFO] GCLOUD: 4153447.729890433 295011.4801210027
[INFO] GCLOUD: 4153449.72871882 294955.95932889543
[INFO] GCLOUD: [4153448.7293046266, 294983.7197249491]

所以现在我正在尝试将此点转换为纬度和经度点以将其放在谷歌地图上,但我不知道如何做到这一点以及是否已经存在用于双向定位的 Java 库?

编辑 :

所以我做到了:

private static final double EARTH_RADIUS = 6371; 

private static final int X = 0;
private static final int Y = 1;
private static final int Z = 2;

public static double[] triangulation(double lat0, double lon0, double r0, double lat1, double lon1, double r1) {
    double[] p1 = latlon2cartesian(lat0, lon0);
    double[] p2 = latlon2cartesian(lat1, lon1);

    double[][] positions = new double[][] { { p1[X], p1[Y], p1[Z] }, { p2[X], p2[Y], p2[Z] } };
    double[] distances = new double[] { r0, r1};

    NonLinearLeastSquaresSolver solver = new NonLinearLeastSquaresSolver(new TrilaterationFunction(positions, distances), new LevenbergMarquardtOptimizer());
    Optimum optimum = solver.solve();

    double[] centroid = optimum.getPoint().toArray();
    System.out.println(Arrays.toString(p1));
    System.out.println(Arrays.toString(p2));
    System.out.println(Arrays.toString(centroid));
    return cartesian2latlon(centroid[X], centroid[Y], centroid[Z]);
}

private static double[] latlon2cartesian(double lat, double lon) {
    lat = Math.toRadians(lat);
    lon = Math.toRadians(lon);
    return new double[] { Math.cos(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lon) * Math.cos(lat) * EARTH_RADIUS, Math.sin(lat) * EARTH_RADIUS };
}

private static double[] cartesian2latlon(double x, double y, double z) {
    return new double[] { Math.toDegrees(Math.asin(z / EARTH_RADIUS)), Math.toDegrees(Math.atan2(y, x)) };
}

但我没有得到正确的值:

System.out.println(Arrays.toString(Bilateration.triangulation(49.243828, 4.062787, 5.0, 49.243851, 4.062023, 6.5)));

我得到:

[49.2453096100026, 3.9213007384886387]

近(2 公里外),但该点应在 49.24385234064716、4.062335368930235 附近。

4

0 回答 0