Private Const Double Earth_radius = 6378.137;
private static Double rad (double D)
{
return d * math.pi/180.0;
}
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;
}
Easy to change into SQL statements
Suppose you calculate the distance between 118.041 36.793 and the punctuation in the database
Mysql> Select 6378137*2*asin (Sqrt ((36.793-domlat) *pi ()/360), 2) + Cos (36.793*pi ()/180) *cos (Domlat*pi () /180) *power (sin (118.041-domlon) *pi ()/360), 2)) as DISTANCE,DOMIP from Dominfo order by distance;
Cut it out.
Select 12756274*asin (Sqrt (36.793-domlat) *0.008726646, 2) + Cos (36.793*0.0174533) *cos (domlat*0.0174533) *power ((118.041-domlon) *0.008726646), 2)) as DISTANCE,DOMIP from Dominfo order by distance;