Created
June 9, 2015 04:34
-
-
Save rizviiqubal/a0131e1fe08ef81e0565 to your computer and use it in GitHub Desktop.
Calculate Distance between two Lat/Longs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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