【问题标题】:Find min and max latitude and longitude in java from given latitude , longitude and radius values从给定的纬度,经度和半径值查找Java中的最小和最大纬度和经度
【发布时间】:2014-04-08 06:56:34
【问题描述】:

我可以找到与纬度和经度的距离(即分别为 minLatitude、minLongitude、maxLatitude 和 maxLongitude),但我需要示例 java 代码来从输入的 latitude、longitude 和 radius 值中找到 minLatitude、minLongitude、maxLatitude 和 maxLongitude。

这是从 lat1、long1、lat2 和 lang2 值中查找距离的代码。

public static double distance(double lat1, double lon1, double lat2, double lon2) {
        double dLat = Math.toRadians(lat2 - lat1);
        double dLon = Math.toRadians(lon2 - lon1);
        lat1 = Math.toRadians(lat1);
        lat2 = Math.toRadians(lat2);

        double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2);
    double c = 2 * Math.asin(Math.sqrt(a));
    return R * c;
}

【问题讨论】:

  • 虽然在另一种编程语言中,我认为this might help 实现了同样的事情,而且代码有点简单

标签: java spring jakarta-ee


【解决方案1】:

尝试类似:

/** returns minLatitude, maxLatitude, minLongitude, maxLongitude */
public double[] calculateMinMaxValues(double latitude , double longitude, double radius){
    double[] res = new double[4];
    res[0] /*minLatitude*/ = latitude - (radius*2)/60.0;
    res[1] /*maxLatitude*/ = latitude + (radius*2)/60.0;

    res[2] /*minLongitude*/ = (longitude*2)/60.0 *(Math.cos(res[0]));
    res[3] /*maxLongitude*/ = (longitude*2)/60.0 *(Math.cos(res[1]));
    return res;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-08-18
    • 2018-09-09
    • 2014-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多