您的位置:首页 > 数据库 > MySQL

附近的人计算方法-----使用mysql脚本计算方法

2016-04-21 00:00 453 查看
附近的人计算方法

drop functionif exists getDistance;

DELIMITER $$

CREATEDEFINER=`root`@`localhost`FUNCTION`getDistance`(

lon1float(10,7)

,lat1float(10,7)

,lon2float(10,7)

,lat2float(10,7)

)RETURNSdouble

begin

declareddouble;

declareradiusint;

setradius = 6378140; #假设地球为正球形,直径为6378140米

setd = (2*ATAN2(SQRT(SIN((lat1-lat2)*PI()/180/2)

*SIN((lat1-lat2)*PI()/180/2)+

COS(lat2*PI()/180)*COS(lat1*PI()/180)

*SIN((lon1-lon2)*PI()/180/2)

*SIN((lon1-lon2)*PI()/180/2)),

SQRT(1-SIN((lat1-lat2)*PI()/180/2)

*SIN((lat1-lat2)*PI()/180/2)

+COS(lat2*PI()/180)*COS(lat1*PI()/180)

*SIN((lon1-lon2)*PI()/180/2)

*SIN((lon1-lon2)*PI()/180/2))))*radius;

returnd;

end

$$

DELIMITER ;

selectgetDistance(116.3899,39.91578,116.3904,39.91576);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: