使用 Geocoder 进行 Mongoid 查询

发布于 2024-11-08 02:58:48 字数 632 浏览 0 评论 0原文

我一直在浏览 mongoid 文档、Geocoder 文档,并询问了一位朋友,但我仍然对此有些困惑。我有两个模型,Event 和 Place:

class Event
  include Mongoid::Document
  belongs_to :place
end

class Place
  include Mongoid::Document
  has_many :events
end

我已经设置了它们,以便 Event.placePlace.events 正常工作,但让我困惑的是将地理编码器附近方法合并到查询中。目前 Place.near(location) 工作正常,我想做的是按位置查询事件,所以 Event.place.near(location)

我已经尝试查看以下内容:

@events = Event.where('event.place' => close(location)

@events = Event.where(place.near(location))< /code>

任何帮助将不胜感激。

I've been going through the mongoid docs, Geocoder docs and have asked a friend, but am still a little stuck on this. I've got two Models, Event and Place:

class Event
  include Mongoid::Document
  belongs_to :place
end

class Place
  include Mongoid::Document
  has_many :events
end

I've set these up so that Event.place and Place.events work fine, the thing that is throwing me is incorporating the Geocoder near method into queries. Currently Place.near(location) works fine, what I'm wanting to do is query Events by their location, so Event.place.near(location)

I've tried looking at things like:

@events = Event.where('event.place' => near(location)

@events = Event.where(place.near(location))

Any help would be appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

大姐,你呐 2024-11-15 02:58:48

这不是吗

place.near(location).events.all

?您可以查询类似的事件

place.near(location).events.where(....

Wouldn't this to be

place.near(location).events.all

and you can query the events like

place.near(location).events.where(....
我早已燃尽 2024-11-15 02:58:48

在处理 mongoDB 中的地理编码器和位置时,您可以受益的一个非常有用的宝石:

https://github.com/ ryanong/mongoid_spacial

A very useful gem you could benefit for when dealing with Geocoder and locations in general within mongoDB :

https://github.com/ryanong/mongoid_spacial

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文