【发布时间】: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