【问题标题】:Is it possible to do geospatial queries in sanity.io?是否可以在 sanity.io 中进行地理空间查询?
【发布时间】:2019-07-18 13:56:25
【问题描述】:

我发现 sanity 支持Geopoint type,但是如果可以对这种类型进行任何过滤操作,我找不到任何信息。可以进行地理空间查询吗?

【问题讨论】:

    标签: sanity groq


    【解决方案1】:

    更简单的地理空间查询语法已在路线图中。

    例如,如果您想进行 Lat/Lng 有界查询,您可以按照以下方式进行,给定架构:

    export default {
       name: 'aDocumentType',
       type: 'document',
       fields: [
        {
           name: 'position',
           type: 'geopoint'
        }
       ]
    }
    

    假设我们使用了 Mapbox,并且有一个 LngLatBounds 对象。现在我们可以使用映射到该对象的params 进行查询:

    *[
      _type == "aDocumentType &&
      position.lng < $bounds._ne.lng &&
      position.lat < $bounds._ne.lat &&
      position.lng > $bounds._sw.lng &&
      position.lat > $bounds._sw.lat &&
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-02
      • 2014-01-29
      • 1970-01-01
      • 2018-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多