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;
}
How to calculate the distance between two coordinates?
Followclose
Comments
0 comments
Please sign in to leave a comment.