mysql 求2个坐标之间的距离
CREATE DEFINER=`root`@`%` FUNCTION `f_GetDistance`(lng1 DOUBLE,lat1 DOUBLE,lng2 DOUBLE,lat2 DOUBLE) RETURNS double
BEGIN
-- select tmm_test.f_GetDistance(119.993633,30.281223,120.03270726,30.28528736);
-- select tmm_test.f_GetDistance(119.993633,30.281223,107.735181,29.871416);
DECLARE radLat1 DOUBLE;
DECLARE radLat2 DOUBLE;
DECLARE a DOUBLE;
DECLARE b DOUBLE;
DECLARE s DOUBLE;
set radLat1 = lat1 * PI() / 180.0;
set radLat2 = lat2 * PI() / 180.0;
set a = radLat1 - radLat2;
set b = lng1* PI() / 180.0 - lng2* PI() / 180.0;
set s = 2 * ASIN(SQRT(POW(SIN(a/2),2) + cos(radLat1)*cos(radLat2)*pow(sin(b/2),2)));
set s = s * 6378137.0;
set s = s/1000;
RETURN s;
END