Created
April 20, 2012 22:04
-
-
Save derencius/2432213 to your computer and use it in GitHub Desktop.
latitude/longitude distance function - for mysql (original source: http://derickrethans.nl/spatial-indexes-mysql.html - syntax changed to fit in 1 line for easy use in a rails migration).
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 distance (latA double, lonA double, latB double, LonB double) | |
RETURNS double DETERMINISTIC | |
RETURN 2 * ASIN(SQRT((SIN((radians(latA) - radians(latB))/2) * SIN((radians(latA) - radians(latB))/2) + | |
COS(radians(latA)) * COS(radians(latB)) * SIN((radians(lonA) - radians(LonB))/2)*SIN((radians(lonA) - radians(LonB))/2)))) * 6371.01 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment