Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

地理位置距离计算 #7

Open
CrossLee opened this issue Jan 25, 2021 · 1 comment
Open

地理位置距离计算 #7

CrossLee opened this issue Jan 25, 2021 · 1 comment

Comments

@CrossLee
Copy link

类似:

/**
 * 计算两点距离
 */
public class GeoTool {
    /**
     *
     */
    private static final double EARTH_RADIUS = 6378.137;


    /**
     * 计算两点之间距离
     * @param lng1
     * @param lat1
     * @param lng2
     * @param lat2
     * @return
     */
    public static double
    getPointDistance(double lng1, double lat1, double lng2, double lat2) {
        double result = 0;
        double radLat1 = radian(lat1);
        double ratlat2 = radian(lat2);
        double a = radian(lat1) - radian(lat2);
        double b = radian(lng1) - radian(lng2);
        result = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
                + Math.cos(radLat1) * Math.cos(ratlat2)
                * Math.pow(Math.sin(b / 2), 2)));
        result = result * EARTH_RADIUS;
        result = Math.round(result * 1000);
        return result;
    }

    //  转换为弧度

    private static double radian(double d) {
        return (d * Math.PI) / 180.00;
    }
}
@fullee
Copy link

fullee commented Feb 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants