Skip to content

Instantly share code, notes, and snippets.

@pedrokoblitz
Created September 20, 2012 18:47
Show Gist options
  • Save pedrokoblitz/3757634 to your computer and use it in GitHub Desktop.
Save pedrokoblitz/3757634 to your computer and use it in GitHub Desktop.
Calculate Distance In Mysql with Latitude and Longitude
SELECT ((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180) + COS($lat * PI() / 180) * COS(lat * PI() / 180) * COS(($lon – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS `distance` FROM `members` HAVING `distance`<=’10′ ORDER BY `distance` ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment