Skip to content

Instantly share code, notes, and snippets.

@antoniodipinto
Created August 30, 2016 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antoniodipinto/cae89efdd4b906011aba05aca38bdfc8 to your computer and use it in GitHub Desktop.
Save antoniodipinto/cae89efdd4b906011aba05aca38bdfc8 to your computer and use it in GitHub Desktop.
This query return the distance between two cordinates
#This query return the distance between two cordinates
SELECT *,
(((acos(sin((LATITUDE_VALUE*pi()/180)) * sin(('nome_colonna_latitudine'*pi()/180))+cos((LATITUDE_VALUE*pi()/180)) * cos(('nome_colonna_latitudine'*pi()/180)) * cos(((LONGITUDE_VALUE- 'nome_colonna_longitudine'e)*pi()/180))))*180/pi())*60*1.1515*1.609344)
as distance
FROM coordinates_table
ORDER BY distance ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment