mysql 根据坐标计算距离函数

CREATE DEFINER=`root`@`%` FUNCTION `getDistance`(curLat DOUBLE, curLon DOUBLE, targetLat DOUBLE, targetLon DOUBLE) RETURNS double
BEGIN  
  DECLARE  dis DOUBLE;  
    IF curLat= 0 or curLon=0 OR IFNULL(targetLat,0)=0 OR IFNULL(targetLon,0)=0 THEN
      SET dis = 0;
    else
      set dis = ROUND(ACOS(SIN((curLat * 3.1415) / 180 ) * SIN((targetLat * 3.1415) / 180 ) + COS((curLat * 3.1415) / 180 ) * COS((targetLat * 3.1415) / 180 ) * COS((curLon * 3.1415) / 180 - (targetLon * 3.1415) / 180 ) ) * 6378138,2) ;  
    END IF;
    RETURN dis;  
END

调用语句

getDistance(比对源.coord_x,比对源.coord_y,当前.coord_x,当前.coord_y)

 

上一篇:Typescript中Partial, Readonly, Record, Pick


下一篇:使用Maya和Substance Painter制作一辆越野赛车(2)