Ruby on rails 使用rails gem geokit按距离和分页排序?

Ruby on rails 使用rails gem geokit按距离和分页排序?,ruby-on-rails,pagination,geokit,Ruby On Rails,Pagination,Geokit,我在我的应用程序中遇到了一个小问题。我目前正在使用geokit查找给定位置附近的对象,并使用查找集上的“按距离排序” 见下文: @find = Item.find(:all, :origin =>[self.geocode.lat.to_f,self.geocode.lng.to_f], :within=>50, :include=>[:programs], :conditions=>["programs.name = ?", self.name]) @find.so

我在我的应用程序中遇到了一个小问题。我目前正在使用geokit查找给定位置附近的对象,并使用查找集上的“按距离排序”

见下文:

@find = Item.find(:all, :origin =>[self.geocode.lat.to_f,self.geocode.lng.to_f], :within=>50, :include=>[:programs], :conditions=>["programs.name = ?", self.name])
  @find.sort_by_distance_from([self.geocode.lat.to_f,self.geocode.lng.to_f]
当按距离排序时,geokit是否有办法从数据库中分页


AKA,没有调用完整的find集?

我解决这个问题的方法是使用find()的:offset和:limit参数

此外,geokit模型还有一个距离字段,:order=>“距离asc”

例如


“距离”列不再工作:

“在当前版本的geokit rails中,无法使用“距离”列添加where子句。我尝试了许多不同的方法,但都没有成功。”

对于where和order子句,其行为方式相同

您可能希望构建这样的查询:

scoped  = Location.geo_scope(:origin => @somewhere)
scoped  = scoped.where('distance <= 5')
results = scoped.all

我也在寻找解决方案。与will_paginate组合会产生不正确的结果。distance列不再起作用:“在当前版本的geokit rails中,无法使用distance列添加where子句。我尝试了许多不同的方法来实现这一点,但没有成功。”where和order子句的行为方式相同。
scoped  = Location.geo_scope(:origin => @somewhere)
scoped  = scoped.where('distance <= 5')
results = scoped.all
scoped = Location.within(5, :origin => @somewhere)
results = scoped.all