Rails, Geocoder and nearby


I'm having a slight issue trying to display certain locations based on proximity to a user. In my controller I have this:

  if User.find(current_user)
    @user = User.find(current_user)
    @locations = Location.near(params[:latitude => @user.latitude, :longitude => @user.longitude], 50, :order => :distance)

Users have a latitude and longitude stored. I'm thinking I've not got the right parameters in the Location.near line, but I can't figure out what they should be.

Any help would be appreciated.


Lets try re-writing that a bit, current_user should already be set, no need for calling User.find. Then it looks like you can pass lat,long as an array

 @locations = Location.near([current_user.latitude, current_user.longitude], 50, :order => :distance)



https://github.com/alexreisner/geocoder (check the readme)