Home > Database > Mysql Tutorial > 附近的人计算方法-----使用mysql脚本计算方法

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

WBOY
Release: 2016-06-07 16:00:01
Original
1038 people have browsed it

附近的人计算方法drop function if exists getDistance;DELIMITER $$ CREATE DEFINER=`root`@`localhost` FUNCTION `getDistance`( lon1 float(10,7) ,lat1 float(10,7) ,lon2 float(10,7) ,lat2 float(10,7)) RETURNS doublebegin declare d double; declar

附近的人计算方法
drop  function if exists getDistance;
DELIMITER $$  
CREATE DEFINER=`root`@`localhost` FUNCTION `getDistance`(
     lon1 float(10,7) 
    ,lat1 float(10,7)
    ,lon2 float(10,7) 
    ,lat2 float(10,7)
) RETURNS double
begin
    declare d double;
    declare radius int;
    set radius = 6378140; #假设地球为正球形,直径为6378140米
    set d = (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;
    return d;
end
$$
DELIMITER ; 
select getDistance(116.3899,39.91578,116.3904,39.91576);
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template