【发布时间】: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
有其他人看到这个问题和/或找到解决方案吗?
【问题讨论】: