我正在使用 GeoFire 搜索给定的半径,用户可以在我的应用程序中设置并存储在 FireBase 上。当页面加载时,在运行 GeoFire 查询之前,我从 Firebase 获取半径。但是,当我运行下面的代码时,我收到以下错误:由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“精度必须小于 23!”
通过玩一些策略性放置的打印语句,看起来 searchRadius 在 GeoFire 查询运行时返回为 0,这让我怀疑异步加载正在发挥作用。
我的问题是,由于我的 searchRadius 为 0,我是否会收到此错误,如果是这样,我如何确保获取我的用户搜索半径的 FireBase 块在我的 GeoFire 查询之前运行?
self.ref.childByAppendingPath("users/\(self.ref.authData.uid)/searchRadius").observeEventType(.Value, withBlock: { snapshot in
self.searchRadius = snapshot.value as! Double
})
let center = CLLocation(latitude: 37.331469, longitude: -122.029825)
let circleQuery = geoFire.queryAtLocation(center, withRadius: self.searchRadius)
circleQuery.observeEventType(GFEventTypeKeyEntered, withBlock: { (key: String!, location: CLLocation!) in
//Do code for each result returned
}) //End GeoFire query