Skip to content

Instantly share code, notes, and snippets.

@b22n
Last active February 13, 2017 04:29
Show Gist options
  • Save b22n/2dcf36c2f26860323bf2 to your computer and use it in GitHub Desktop.
Save b22n/2dcf36c2f26860323bf2 to your computer and use it in GitHub Desktop.
SQL Function: Distance in meters between two Geo Points
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