Ruby on Rails的 - 地理codeR - 近与条件 [英] Ruby On Rails - Geocoder - Near with condition

查看:192
本文介绍了Ruby on Rails的 - 地理codeR - 近与条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是地缘codeR在我的应用程序。现在,我需要寻找在我的数据库,其中有接近位置或具有特定属性集的对象。我想执行一个数据库查询这个动作,因为数据库是真的很大。

I'm using GeoCoder in my application. Now I need to search for objects in my database which are close to a position OR have specific attribute set. I would like to perform this action in one database query, because the database is realy huge.

我想有像

  Spot.near([lat,long],distance).where("visited = ?",true). 

的距离和被访问的属性应该用一个OR结合,而不是与一个AND

The distance and the visited attribute should be combined with an OR, not with an AND.

有没有人有一个想法如何做到这一点?

Does anyone have an idea how to do this?

感谢您!

推荐答案

根据关这个的答案,你应该能够做到这样的:

Based off of this answer, you should be able to do something like:

near = Spot.near([lat, long], distance)
visited = Spot.where(visited: true)

near = near.where_values.reduce(:and)
visited = visited.where_values.reduce(:and)

Spot.where(near.or(visited))

这篇关于Ruby on Rails的 - 地理codeR - 近与条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆