Last active
February 13, 2017 04:29
-
-
Save b22n/2dcf36c2f26860323bf2 to your computer and use it in GitHub Desktop.
SQL Function: Distance in 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`(point1 POINT, point2 POINT) RETURNS NUMERIC | |
RETURN 6371000 * 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