【问题标题】:Java Geolocation calculation - not getting the right valuesJava Geolocation 计算 - 没有得到正确的值
【发布时间】:2019-12-05 13:18:42
【问题描述】:

我有一个飞行管理系统的 Javafx 应用程序,我必须计算机场之间的距离,例如从杜塞尔多夫国际机场到科隆机场,我尝试了从这里的帖子中找到的 Geodys api,但它没有给我所需的值。有人可以给我一个关于这个问题的指针吗?我有从我的数据库中提供的纬度和经度。

这是 Api 代码:

public double distanceCalculator() throws SQLException {

        Statement disanceState = connection.createStatement();
        ResultSet startFlughafen = disanceState
                .executeQuery("select * from flughaefen where name  =\"" + startAirport.getValue() + "\"");
        while (startFlughafen.next()) {
            longitudeStart = startFlughafen.getDouble("lon");
            latidudeStart = startFlughafen.getDouble("lat");

        }
        ResultSet zielFlughafen = disanceState
                .executeQuery("select * from flughaefen where name  =\"" + targetAirport.getValue() + "\"");
        while (zielFlughafen.next()) {
            longitudeZiel = zielFlughafen.getDouble("lon");
            latidudeZiel = zielFlughafen.getDouble("lat");

        }

        GeodeticCalculator geoCalc = new GeodeticCalculator();

        Ellipsoid reference = Ellipsoid.WGS84;

        GlobalPosition startFlughafenValues = new GlobalPosition(latidudeStart, longitudeStart, 0.0); // Point A

        GlobalPosition zielFlughafenValues = new GlobalPosition(latidudeZiel, longitudeZiel, 0.0); // Point B

        distanceSet = geoCalc.calculateGeodeticCurve(reference, startFlughafenValues, zielFlughafenValues)
                .getEllipsoidalDistance(); // Distance between Point A and Point B

        return distanceSet;
    }

这是我尝试过的另一个公式:

public double distanceCalculator() throws SQLException {    

        Statement disanceState = connection.createStatement();
        ResultSet startFlughafen = disanceState
                .executeQuery("select * from flughaefen where name  =\"" + startAirport.getValue() + "\"");
        while (startFlughafen.next()) {
             longitudeStart = startFlughafen.getDouble("lon");
             latidudeStart = startFlughafen.getDouble("lat");

        }
        ResultSet zielFlughafen = disanceState
                .executeQuery("select * from flughaefen where name  =\"" + targetAirport.getValue() + "\"");
        while (zielFlughafen.next()) {
             longitudeZiel = zielFlughafen.getDouble("lon");
             latidudeZiel = zielFlughafen.getDouble("lat");

        }


        final int R = 6371; // Radius of the earth

        double latDistance = Math.toRadians(latidudeZiel - latidudeStart);
        double lonDistance = Math.toRadians(longitudeZiel - longitudeStart);
        double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
                + Math.cos(Math.toRadians(longitudeStart)) * Math.cos(Math.toRadians(longitudeZiel))
                * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
         distances = R * c ; // convert to meters

         distances = Math.pow(distances, 2) ;

         return Math.sqrt(distances);

【问题讨论】:

    标签: java javafx geolocation maps


    【解决方案1】:

    有几个库可以做到这一点,但在后台它们也经常使用 GeographicLib:https://geographiclib.sourceforge.io/ 可以在文本中找到指向 Java 版本的链接。您可能正在寻找的类称为 Geodesic。

    【讨论】:

      猜你喜欢
      • 2017-10-24
      • 2013-09-20
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2019-07-20
      • 1970-01-01
      • 2022-10-19
      • 2022-08-16
      相关资源
      最近更新 更多