Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Calculate Distance between two Lat/Longs
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment