1, calculate the distance formula is long (on-line search), build a MySQL function:
Delimiter $ $CREATE FUNCTION fun_jw_dist (lng1 double (15,9), LAT1 double (9), Lng2 double (15,9), Lat2 double (15,9)) RETURNS double (15,9) BEGIN DECLARE Dist Double (9); SET dist = round (6378.138*2*asin (sqrt (Pow ((Lat1*pi ()/180-lat2*pi ()/180)/2), 2) +cos (Lat1*pi ()/180) *cos (Lat2*pi ( )/180) * POW (Sin ((Lng1*pi ()/180-lng2*pi ()/180)/2), 2)) (*1000)); RETURN (Dist); end$ $delimiter;
Test:
For example:
1th (116.359751000, 39.936868000) 2nd (117.291179000, 35.657141000)
Executes a select round (6378.138*2*asin (sqrt (39.936868000*pi ()/180-35.657141000*pi ()/180)/2 in the database, 2) +cos ( 39.936868000*pi ()/180) *cos (35.657141000*pi ()/180) * POW (Sin ((116.359751000*pi ()/180-117.291179000*pi ()/180)/2), 2 ))) *1000)
Execution Result: 483402
Performed: Select Fun_jw_dist (116.359751000, 39.936868000, 117.291179000, 35.657141000);
Execution Result: 483402.000000000
MySQL calculates the distance between latitude and longitude highlights