Skip to content

Instantly share code, notes, and snippets.

@donniebrandt
Last active December 28, 2015 03:29
Show Gist options
  • Select an option

  • Save donniebrandt/7435655 to your computer and use it in GitHub Desktop.

Select an option

Save donniebrandt/7435655 to your computer and use it in GitHub Desktop.
MySQL: Coordinates and distance.
SELECT
latitude,
longitude
(3959
* ACOS(COS(RADIANS(%.6f /*Lat*/))
* COS(RADIANS(latitude))
* COS(RADIANS(longitude) - RADIANS(%.6f /*Long*/)) + SIN(RADIANS(%.6f /*Lat*/))
* SIN(RADIANS(latitude)))) AS distance
FROM coordinates
WHERE latitude BETWEEN %.6f AND %.6f
AND longitude BETWEEN %.6f AND %.6f
ORDER BY distance ASC
LIMIT 5;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment