加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 01:58:01 所属栏目:百科 来源:网络整理
导读:我在我的应用中遇到了一个小问题.我目前正在使用geokit查找给定位置附近的对象,并在找到的集合上使用sort_by_distance_from. 见下文: @find = Item.find(:all,:origin =[self.geocode.lat.to_f,self.geocode.lng.to_f],:within=50,:include=[:programs],:co
我在我的应用中遇到了一个小问题.我目前正在使用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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读