【问题标题】:GeoFire Circle Query NSExceptionGeoFire Circle 查询 NSException
【发布时间】:2019-12-27 00:12:56
【问题描述】:

我在我的 Swift 应用程序中使用 Firebase 和 GeoFire 3.0 Cocoapod 来使用世界各地的标记填充地图。下面是执行圆形查询以获取地图上当前显示区域内的标记的代码:

        dbRef = Database.database().reference()
        let geoRef = GeoFire(firebaseRef: dbRef.child("markers"))
        let center = CLLocation(latitude: currentLocation.latitude, longitude: currentLocation.longitude)
        print("Center: "," Lat: ",currentLocation.latitude," Long: ",currentLocation.longitude )
        let circleQuery = geoRef.query(at: center, withRadius: 100)
        circleQuery.observe(.keyEntered, with: { key, location in
            print("key: ",key,"Location: ",location)
            let markerKey = key
            let markerLat = location.coordinate.latitude
            let markerLong = location.coordinate.longitude
            //read "verified" flag from firebase record "key"
            self.dbRef.child(markerKey).observeSingleEvent(of: .value, with: { (snapshot) in
                let value = snapshot.value as? NSDictionary
                let verified = value?["verified"] as? Bool
                print("key: ",key,"Location: ",location,"verified: ",verified as Any)
                ...
            })
         })

当用户缩小圆形查询以显示整个世界的地图(半径为 8000 公里(4791 英里))时,查询会因 NSException 而中止。

Xcode 调试器显示 GeoFire 计算出的纬度为 105.9793939... 经度为 -112.05707936...

Geofire 应将纬度限制在 +/- 90,将经度限制在 +/- 180,在这种情况下,应从查询返回所有 GeoFire 数据。

这是 Xcode 中的错误截图: Xcode Error Screenshot

有其他人看到这个问题和/或找到解决方案吗?

【问题讨论】:

    标签: swift firebase geofire


    【解决方案1】:

    由于 GeoFire 明确以您想要的方式限制纬度和经度,您有两种选择

    1. 在 GeoFire 存储库上报告问题,并可能自己提出 PR。
    2. 将值限制在您自己的应用程序代码中所需的范围内。

    我建议采用第二种方法,因为无论如何您都希望/需要表明您在 UI 中剪切/限制了范围。

    【讨论】:

    • 谢谢弗兰克。我确实在 GeoFire repo 上报告了这个问题。我需要进一步测试,但不确定在半径小于地球直径的情况下如何限制它。下周我将尝试找一些时间来深入研究这个问题并提出解决方案。可惜它不能正常工作,因为它似乎是我们应用的一个很好的解决方案。
    猜你喜欢
    • 2016-07-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    • 1970-01-01
    • 2017-09-19
    • 2019-02-01
    • 2018-05-12
    相关资源
    最近更新 更多