# 角度

``````/*
* 计算两点对于正北方向的朝向角度 [0,360]
* @param {*} start format:{'latitude': 30, 'longitude': 120 }
* @param {*} end
*/
private static double bearing(List<Double> start, List<Double> end) {

double rad = Math.PI / 180,
double a = Math.sin(lon2 - lon1) * Math.cos(lat2);
double b = Math.cos(lat1) * Math.sin(lat2) -
Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1);
if (angle < 0) {

angle = 360 + angle;
}
return angle;
}
/*
* 弧度转换为角度
*/

double degrees = radians % (2 * Math.PI);
return degrees * 180 / Math.PI;
}
``````

# 距离

``````    /**
*
* @param long1 经度1
* @param lat1 纬度1
* @param long2 经度2
* @param lat2 纬度2
* @return 米
*/
public static double getDistance(double long1, double lat1, double long2, double lat2) {

double a, b, R;
R = 6378137; // 地球半径
lat1 = lat1 * Math.PI / 180.0;
lat2 = lat2 * Math.PI / 180.0;
a = lat1 - lat2;
b = (long1 - long2) * Math.PI / 180.0;
double d;
double sa2, sb2;
sa2 = Math.sin(a / 2.0);
sb2 = Math.sin(b / 2.0);
d = 2 * R * Math.asin(Math.sqrt(sa2 * sa2 + Math.cos(lat1) * Math.cos(lat2) * sb2 * sb2));
return d;
}
``````