Java known two locations latitude and longitude distance (very accurate)
Package com.lbnet.lzx.util;
public class GoogleMap {
Private static final Double Earth_radius = 6378.137;
private static Double rad (double D)
{
return d * math.pi/180.0;
}
/**
* ????}????????????? /γ???
* @param LAT1
* @param lng1
* @param lat2
* @param lng2
* @return
*/
public static double Getdistance (double lat1, double lng1, double lat2, double lng2)
{
Double RADLAT1 = rad (LAT1);
Double radLat2 = rad (LAT2);
Double A = RADLAT1-RADLAT2;
Double b = rad (lng1)-Rad (LNG2);
Double s = 2 * Math.asin (MATH.SQRT (Math.pow (Math.sin (A/2), 2) +
Math.Cos (RADLAT1) *math.cos (RADLAT2) *math.pow (Math.sin (B/2), 2));
s = S * earth_radius;
s = Math.Round (S * 10000)/10000;
return s;
}
public static double D_jw (double wd1,double jd1,double wd2,double JD2)
{
Double x,y,out;
Double pi=3.14159265;
Double r=6.371229*1e6;
x= (JD2-JD1) *pi*r*math.cos ((WD1+WD2)/2) *pi/180)/180;
Y= (WD2-WD1) *pi*r/180;
Out=math.hypot (X,y);
return out/1000;
}
public static void Main (String args[]) {
31.1795100,121.3944810
System.out.println (GOOGLEMAP.D_JW (31.192609,121.431577,31.1822952,121.4314814));
}
}