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 sort 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/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.