Nearby people calculation method drop function if exists getdistance;delimiter $$ CREATE definer= ' root ' @ ' localhost ' function ' Getdistance ' ( lon1 float (10,7) , lat1 float (10,7) , Lon2 float (10,7) , Lat2 float (10,7)) RETURNS Doublebegin declare d double; declare radius int; Set radius = 6378140; #如果地球为正球形. The diameter is 6378140 meters Set d = (2*atan2 (SQRT (SIN (LAT1-LAT2) *pi ()/180/2) *sin ((LAT1-LAT2) *pi ()/180/2) + COS ( Lat2*pi ()/180) *cos (Lat1*pi ()/180) *sin ((lon1-lon2) *pi ()/180/2) *sin ((lon1-lon2) *pi ()/180/2), SQRT (1-sin ((LAT1-LAT2) *pi ()/180/2) *sin ((LAT1-LAT2) *pi ()/180/2) +cos (Lat2*pi ()/180) *cos (Lat1*pi ()/ *sin ((lon1-lon2) *pi ()/180/2) *sin ((lon1-lon2) *pi ()/180/2))) *radius; return d;end$ $DELIMITER; Select Getdistance (116.3899,39.91578,116.3904,39.91576);
Nearby people calculation method-----Using MySQL Script calculation method