Created
April 27, 2015 07:59
-
-
Save gergelypolonkai/bdad1cf2d410853bef35 to your computer and use it in GitHub Desktop.
MySQL Haversine function
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
DELIMITER $$ | |
CREATE FUNCTION `haversine` (lng1 FLOAT, lat1 FLOAT, lng2 FLOAT, lat2 FLOAT) | |
RETURNS float NO SQL DETERMINISTIC | |
BEGIN | |
SET @a = ABS(POWER(SIN(RADIANS(lat1 - lat2)) / 2, 2) + COS(RADIANS(lat1)) * COS(RADIANS(lat2)) * POWER(SIN(RADIANS(lng1 - lng2)) / 2, 2)); | |
RETURN 12756.200 * ATAN2(SQRT(@a), SQRT(1 - @a)); | |
END$$ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment