Last active
February 13, 2017 04:30
-
-
Save b22n/8a463dc7436bc3a866bb to your computer and use it in GitHub Desktop.
SQL Function: Distance in kilo meters between two Geo Points
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 FUNCTION `GEO_DISTANCE_KM`(point1 POINT, point2 POINT) RETURNS NUMERIC | |
RETURN 6371 * acos( | |
cos(radians(X(point2))) | |
* cos(radians(X(point1))) | |
* cos(radians(Y(point1)) - radians(Y(point2))) | |
+ sin(radians(X(point2))) | |
* sin(radians(X(point1))) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment