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

标签 ruby-on-rails pagination geokit

我在我的应用程序中遇到了一个小问题。我目前正在使用 geokit 来查找给定位置附近的对象,并在搜索结果上使用 sort_by_distance_from。

见下文:

@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,不是调用完整的搜索结果集?

最佳答案

距离列不再起作用:

"In the current version of geokit-rails, it is not possible to add a where clause using the distance column. I've tried many different ways to do this and didn't get it working."



对于 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

github.com/geokit/geokit-rails

关于ruby-on-rails - 使用 rails gem geokit 按距离和分页排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3792703/

相关文章:

ruby-on-rails - #<Comment :0x007f12ef55d0d0> 的未定义方法 `each'

ruby-on-rails - Rails 基于位置的搜索不适用于 Heroku

sql - 查询不返回 bool 列设置为 FALSE 的记录?

ruby-on-rails - 无法安装 Twilio gem - libxml 问题

database - 即时数据的SQL分页

css - table-header-group , table-footer-group 属性在 Chrome 中不起作用

node.js - 如何在 Telegram 中使用内联键盘创建分页

ruby-on-rails - Geokit plus Rails 3.1.1,纬度和经度问题。

ruby-on-rails - 操作系统 : Rails Layer connect to Elasticache : Redis