java地理方位角度计算

计算方位角度

从一个坐标到另一个坐标的方位角度.

GIS地理 方位角,正北作为0度基线,顺时针旋转。

/**
     * GIS方位角度,正北为0度,顺时针旋转
     *
     * @param lat1 坐标1纬度
     * @param lon1 坐标1经度
     * @param lat2 坐标2纬度
     * @param lon2 坐标2经度
     * @return 坐标1到坐标2方位角度
     */
    public static double bearing(double lat1, double lon1, double lat2, double lon2) {
        double longitude1 = lon1;
        double longitude2 = lon2;
        double latitude1 = Math.toRadians(lat1);
        double latitude2 = Math.toRadians(lat2);
        double longDiff = Math.toRadians(longitude2 - longitude1);
        double y = Math.sin(longDiff) * Math.cos(latitude2);
        double x = Math.cos(latitude1) * Math.sin(latitude2) - Math.sin(latitude1) * Math.cos(latitude2) * Math.cos(longDiff);
        return (Math.toDegrees(Math.atan2(y, x)) + 360) % 360;
    }

测试用例

 //坐标1为北京,坐标2为广州
        double bearing = LBSUtil.bearing(39.923984, 116.534119, 23.140121, 113.29845);
        System.out.println(bearing);//190.2221319576134

在这里插入图片描述
结果北京到广州的方位角度是190.2221319576134度,参考地图,基本符合事实。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值