Created
May 14, 2014 14:31
-
-
Save stfnhh/9768b82ddc0081e11b88 to your computer and use it in GitHub Desktop.
MySQL find distance from latitude and longitude
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
SELECT | |
`locations`.`id` | |
SQRT( | |
POW(69.1 * ( | |
41.7600 - `locations`.`latitude` | |
), 2) + | |
POW(69.1 * ( | |
`locations`.`longitude` - 70.0833) * COS(41.7600 / 57.3), 2) | |
) AS `distance` | |
FROM | |
`locations` | |
WHERE `locations`.`id` = 1 | |
ORDER BY `distance` | |
LIMIT 5; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment