计算方位角度
从一个坐标到另一个坐标的方位角度.
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度,参考地图,基本符合事实。
3457

被折叠的 条评论
为什么被折叠?



