Tuesday, June 09, 2015

Find The Distance Between Two Lat/Long using mysql functions




       

CREATE DEFINER=`root`@`localhost` FUNCTION `mm_calc_distance`(`lat1` double, `long1` double, `lat2` double, `long2` double) RETURNS double
BEGIN
 DECLARE distance_in_km double;
        SELECT 
           111.1111 *
           DEGREES(ACOS(COS(RADIANS(lat1))
           * COS(RADIANS(lat2))
           * COS(RADIANS(long1 - long2))
           + SIN(RADIANS(lat1))
           * SIN(RADIANS(lat2)))) into distance_in_km;


        RETURN distance_in_km;
END

       
 






Gist Github Url For Source Code 

No comments: