CREATE DEFINER=`root`@`localhost` FUNCTION `getDistance`(lng1 float, lat1 float, lng2 float, lat2 float) RETURNS int(11) BEGIN DECLARE result double; DECLARE radLng1 double; DECLARE radLat1 double; DECLARE radLng2 double; DECLARE radLat2 double; set radLng1 = lng1 * pi() / 180.0; set radLat1 = lat1 * pi() / 180.0; set radLng2 = lng2 * pi() / 180.0; set radLat2 = lat2 * pi() / 180.0; set result = 2 * asin(sqrt(pow(sin((radLat1 - radLat2) / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin((radLng1 - radLng2) / 2), 2))); set result = result * 6378.137; set result = round(result * 10000) / 10000; RETURN result; END