Skip to content

Instantly share code, notes, and snippets.

@urieljuliatti
Created September 12, 2013 13:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save urieljuliatti/6536929 to your computer and use it in GitHub Desktop.
Save urieljuliatti/6536929 to your computer and use it in GitHub Desktop.
SELECT *,
( 3959 * acos( cos( radians('#{latitude}') ) *
cos( radians( latitude ) ) *
cos( radians( longitude ) -
radians('#{longitude}') ) +
sin( radians('#{latitude}') ) *
sin( radians( latitude ) ) ) )
AS distance, a_b.name as neighbourhood_name FROM address_neighbourhood_users INNER JOIN address_neighbourhoods AS a_b ON a_b.neighbour_code = address_neighbourhood_users.address_neighbourhood_code AND ( 3959 * acos( cos( radians('#{latitude}') ) *
cos( radians( latitude ) ) *
cos( radians( longitude ) -
radians('#{longitude}') ) +
sin( radians('#{latitude}') ) *
sin( radians( latitude ) ) ) ) < '5' ORDER BY address_neighbourhood_users.id ASC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment