Skip to content

Instantly share code, notes, and snippets.

@stfnhh
Created May 14, 2014 14:31
Show Gist options
  • Save stfnhh/9768b82ddc0081e11b88 to your computer and use it in GitHub Desktop.
Save stfnhh/9768b82ddc0081e11b88 to your computer and use it in GitHub Desktop.
MySQL find distance from latitude and longitude
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