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)