Created
March 16, 2017 05:08
-
-
Save zafe/cc0ee853f791187efc9001e0c10aac73 to your computer and use it in GitHub Desktop.
MySQL function to determine the distance between two points considering Earth's spherical surface.
This file contains hidden or 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
DELIMITER $$ | |
-- Returns value in Km (Kilometers) | |
CREATE FUNCTION distance_points (lat1 FLOAT, lng1 FLOAT, lat2 FLOAT, lng2 FLOAT) | |
RETURNS FLOAT | |
DETERMINISTIC | |
BEGIN | |
RETURN (acos(sin(radians(lat1)) * sin(radians(lat2)) + | |
cos(radians(lat1)) * cos(radians(lat2)) * | |
cos(radians(lng1) - radians(lng2))) * 6371); | |
END$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment