This article describes how to calculate the distance between two points based on the latitude and longitude of python. For more information, see
The code is as follows:
/**
* Calculate the distance between two points
* @ Param _ lat1-start latitude
* @ Param _ lon1-start longitude
* @ Param _ lat2-end latitude
* @ Param _ lon2-end longitude
* @ Return km (rounding)
*/
Public static double getDistance (double _ lat1, double _ lon1, double _ lat2, double _ lon2 ){
Double lat1 = (Math. PI/180) * _ lat1;
Double lat2 = (Math. PI/180) * _ lat2;
Double lon1 = (Math. PI/180) * _ lon1;
Double lon2 = (Math. PI/180) * _ lon2;
// Earth radius
Double R = 6378.1;
Double d = Math. acos (Math. sin (lat1) * Math. sin (lat2) + Math. cos (lat1) * Math. cos (lat2) * Math. cos (lon2-lon1) * R;
Return new BigDecimal (d). setScale (4, BigDecimal. ROUND_HALF_UP). doubleValue ();
}
Public static void main (String [] args ){
System. out. println (getDistance (45.73990, 126.55893, 45.73876, 126.55037 ));
}