private static double degreeToRadian(double degree) {
return degree * (Math.PI / 180.0d);
}
public static double getDistanceInMeterFromTwoGPSLocations(double firstLat, double firstLong, double secondLat, double secondLong) {
// Radius of the Earth in m
final double R = 6371000.0d;
final double dlon = degreeToRadian(secondLong - firstLong);
final double dlat = degreeToRadian(secondLat - firstLat);
final double a = Math.sin(dlat / 2d) * Math.sin(dlat / 2d) + Math.cos(degreeToRadian(firstLat)) * Math.cos(degreeToRadian(secondLat)) * Math.sin(dlon / 2d) * Math.sin(dlon / 2d);
final double c = 2d * Math.atan2(Math.sqrt(a), Math.sqrt(1d - a));
return R * c;
}
如何计算两个坐标之间的距离?
关注close
评论
0 条评论
请登录写评论。