经纬度计算

DELIMITER $$

USE `zbapp`$$

DROP FUNCTION IF EXISTS `getDistance`$$

CREATE DEFINER=`root`@`%` FUNCTION `getDistance`(lat1 DOUBLE,lng1 DOUBLE,lat2 DOUBLE,lng2 DOUBLE) RETURNS DOUBLE
BEGIN
IF(LENGTH(lat1) =0 || LENGTH(lng1) =0 || LENGTH(lat2) =0 || LENGTH(lng2) =0 || lat1 IS NULL|| lng1 IS NULL|| lat2 IS NULL|| lng2 IS NULL) THEN
RETURN -1;
END IF;
RETURN ROUND(6378.138*2*ASIN(SQRT(POW(SIN( (lat1*PI()/180-lat2*PI()/180)/2),2)+COS(lat1*PI()/180)*COS(lat2*PI()/180)* POW(SIN( (lng1*PI()/180-lng2*PI()/180)/2),2)))*1000);
END$$

DELIMITER ;

posted @ 2018-04-28 13:51  陈扬天  阅读(287)  评论(0编辑  收藏  举报