Public double getdistance (double startlat, double startlong, double endlat, double endlong ){
// Startlong start coordinate point longitude
// Start coordinate point dimension of startlat
// Endlong target coordinate point longitude
// Endlat target coordinate point dimension double LAT1 = (math. PI/180) * startlat; double LAT2 = (math. PI/180) * endlat; double lon1 = (math. PI/180) * startlong; double lon2 = (math. PI/180) * endlong; // the radius of the earth is double r = 6371; // the distance between two points is km. If you want the distance between the two points, the result * 1000 is equivalent to double D = math. ACOs (math. sin (LAT1) * Math. sin (LAT2) + math. cos (LAT1) * Math. cos (LAT2) * Math. cos (lon2-lon1) * R; // double S = r * Math. ACOs (math. cos (LAT1 * Math. PI/180) * Math. cos (LAT2 * Math. PI/180) * Math. cos (lng1 * Math. PI/180-lng2 * Math. PI/180) + math. sin (LAT1 * Math. PI/180) * Math. sin (LAT2 * Math. PI/180); Return D * 1000;
}
Calculate the Distance Based on the longitude and latitude