Skip to content

Instantly share code, notes, and snippets.

@michaelaguiar
Created October 5, 2011 00:22
Show Gist options
  • Select an option

  • Save michaelaguiar/1263246 to your computer and use it in GitHub Desktop.

Select an option

Save michaelaguiar/1263246 to your computer and use it in GitHub Desktop.
SQL - Calculate Distance
SELECT *,(((acos(sin((".$latitude."*pi()/180)) * sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180)) * cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM `TABLE` HAVING distance <= ".$distance;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment