Search code examples
ruby-on-railsrubyrails-geocoder

Geocoder Sort By Distance Without Proximity Filter


Using the geocoder gem is it possible to use the distance from a point as a sort criteria but not a filter criteria? I'm looking for a cleaner way than just setting a really large distance like this:

Location.near(coordinates, 8_000_000)

Solution

  • Just pass an order option:

    Location.near(coordinates, 8_000_000 , order: 'distance')
    

    Note that you still have to set a maximum distance though.