Boris Kuzevanov Boris Kuzevanov - 9 months ago 65
Ruby Question

rails Geocoder gem order by location from me

I have Place model with lat and long fields.
So i need to select all places and order them using my geoposition.
I think that i need to use Geocoder gem.

So user send to me his lat & long
and i need to do smth like

Place.where(status: 1).and order them using my lat long.

How can i do?



You would use the near method:

Place.where(status: 1).near( "Party City, Utah", 20 ) # Finds places within 20 miles

This will grab all Place records that are within a specific radius of the given location. In this case, your location is "Party City, Utah". You can add additional arguments to the near method to limit the number of results, and also edit the radius of your query.

More information in the GeoCoder Docs