`

获取两地的距离

    博客分类:
  • Java
 
阅读更多

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;

 

  • 大小: 19.3 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics