mysql 计算2点之间的距离

CREATE DEFINER=`root`@`%` FUNCTION `getDistance`(lat1 DOUBLE,lng1 DOUBLE,lat2 DOUBLE,lng2 DOUBLE,pi DOUBLE) RETURNS double
BEGIN
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(power(sin(a/2),2) +cos(radLat1)*cos(radLat2)*power(sin(b/2),2)));
  set s = s *6378.137 ;
  set s = round(s * 100.0) / 100.0;
RETURN s;
END

你可能感兴趣的:(mysql 计算2点之间的距离)