1.獲取兩個(gè)點(diǎn)的航向角
public static double getAngle1(double latA, double lngA, double latB, double lngB) {
double y = Math.sin(lngB - lngA) * Math.cos(latB);
double x = Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(lngB - lngA);
double bearing = Math.atan2(y, x);
bearing = Math.toDegrees(bearing);
if (bearing < 0) {
bearing = bearing + 360;
}
return bearing;
}
2.獲取兩點(diǎn)的距離
/**
* 得到兩點(diǎn)間距離
* 返回單位是米
*/
public static double getDistance(double longitude1, double latitude1,
double longitude2, double latitude2) {
double lat1 = rad(latitude1);
double lat2 = rad(latitude2);
double a = lat1 - lat2;
double b = rad(longitude1) - rad(longitude2);
double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2)
+ Math.cos(lat1) * Math.cos(lat2)
* Math.pow(Math.sin(b / 2), 2)));
s = s * EARTH_RADIUS;
s = Math.round(s * 10000) / 10000;
TagUtils.aLog("兩點(diǎn)間距離" + s);
return s;
}
private static double rad(double d) {
return d * Math.PI / 180.0;
}