Skip to content

Instantly share code, notes, and snippets.

@rizviiqubal
Created June 9, 2015 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rizviiqubal/a0131e1fe08ef81e0565 to your computer and use it in GitHub Desktop.
Save rizviiqubal/a0131e1fe08ef81e0565 to your computer and use it in GitHub Desktop.
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