获取两地的距离

CREATE DEFINER = `root`@`%` FUNCTION `NewProc`(`lon1` real,`lat1` real,`lon2` real,`lat2` real)

 RETURNS float

BEGIN

#Routine body goes here...

DECLARE dist FLOAT;

  DECLARE radLat1 FLOAT;

DECLARE radLat2 FLOAT;

DECLARE a FLOAT;

DECLARE b FLOAT;

DECLARE radius real;

SET radius = 6371000;

SET radLat1=lat1*PI()/180.0;

SET radLat2=lat2*PI()/180.0;

SET a=radLat1-radLat2;

SET b=lon1*PI()/180.0-lon2*PI()/180.0;

SET dist=2*ASIN(SQRT(POW(SIN(a/2),2)+COS(radLat1)*COS(radLat2)*POW(SIN(b/2),2)));

SET dist=dist*radius;

SET dist=ROUND(dist*10000)/10000;

RETURN dist;

END;

猜你喜欢

转载自yu-zhang430.iteye.com/blog/2251110