我正在使用半正式公式来计算距离,但我得到的距离实际上谷歌地图距离是8.1km,但是半径公式显示为4.06
private static final int EARTH_RADIUS = 6371; // Approx Earth radius in KM
public static double distance(double startLat, double startLong, double endLat, double endLong) {
double dLat = Math.toRadians((endLat - startLat));
double dLong = Math.toRadians((endLong - startLong));
startLat = Math.toRadians(startLat);
endLat = Math.toRadians(endLat);
double a = haversin(dLat) + Math.cos(startLat) * Math.cos(endLat) * haversin(dLong);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return EARTH_RADIUS * c; // <-- d
}
public static double haversin(double val) {
return Math.pow(Math.sin(val / 2), 2);
}