【问题标题】:Firebase query for two valuesFirebase 查询两个值
【发布时间】:2016-12-05 17:19:11
【问题描述】:

我正在尝试在不使用 GeoFire 的情况下在 Firebase 中实现基于位置的查询(因为上次更新是 6 个月前,它似乎已被弃用)

无论如何,我想不通。

它不会触发监听器。 当没有开始或结束时它有效。

查询如下所示:(仅使用 Latitude 进行测试)

// Testing, only doing longtude atm.
        geoFlamesFIRReference
            .queryStarting(atValue: coordinates!.longitude - radius, childKey: "longtitude")
            .queryEnding(atValue: coordinates!.longitude + radius, childKey: "longtitude")
            .queryLimited(toFirst: UInt(Constants.LIMIT_OF_FLAMES_ON_MAP))
            .observe(.value, with: { snapshot in
                print("New location?")
            })

然后是我的一些数据示例:

【问题讨论】:

  • GeoFire 未被弃用。它工作正常,所以暂时不需要更新。

标签: ios swift firebase firebase-realtime-database


【解决方案1】:

您使用了错误的查询语法:

geoFlamesFIRReference
    .queryOrder(byChild: "longtitude")
    .queryStarting(atValue: coordinates!.longitude - radius)
    .queryEnding(atValue: coordinates!.longitude + radius)

请注意,当您还想按纬度过滤时会遇到问题,如Firebase queries can only contain a single orderBy clause

GeoFire 使用geohashes 来解决此限制。因此,如果您打算不使用该库,则必须阅读这些内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-29
    • 2021-03-29
    • 2017-01-07
    • 1970-01-01
    • 2021-01-09
    • 2018-02-26
    • 2018-10-23
    • 1970-01-01
    相关资源
    最近更新 更多