【问题标题】:Using $geoWithin issue mongoid使用 $geoWithin 问题 mongoid
【发布时间】:2014-12-17 08:25:54
【问题描述】:

目前在 Mongoid 中构建了任何方法来使用 $geoWithin 而不在数据库中存储任何内容?

希望能够只使用$geoWithin(或其他类似方法),只需在具有坐标的某个对象上调用它并随后通过多边形边界。

想法?

【问题讨论】:

    标签: ruby mongodb mongoid nosql


    【解决方案1】:

    你用过 geo_near 吗?

    这对我有用

    center = [lat.to_f, lon.to_f]
    User.geo_near(center).max_distance(10)
    

    用户模型定义:

    field :location, type:Array  # [lat,lng]
    index( { location: "2d" }, { min: -180, max: 180 })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-15
      • 2012-07-09
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 2023-03-25
      相关资源
      最近更新 更多