I'm using Geokit. I have the following in my model:
# Distance-based finder method
# Usage:
# - find_this_within(Shop.first, 10)
def self.find_this_within(origin, within)
if origin.geocoded?
find(:all, :origin => origin, :within => within )
else
[]
end
end
Then in my controller:
@shops = s.paginate(:page => params[:page], :per_page => 20)
Currently the output is listed in ID ascending. I want it to sor开发者_C百科t from nearest to furthest. What should I do?
Thanks.
I believe what you are looking for is:
def self.find_this_within(origin, within)
if origin.geocoded?
find(:all, :origin => origin, :within => within, :order => 'distance asc')
else
[]
end
end
Or so say the Docs: http://geokit.rubyforge.org/
精彩评论