我在我的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 Km (4791 MI))时,查询将中止,并显示NSException。
Xcode调试器显示GeoFire计算出的纬度为105.9793939...经度为-112.05707936..。
Geofire应该将纬度限制为+/- 90,将经度限制为+/- 180,在这种情况下,应该从查询中返回所有GeoFire数据。
下面是Xcode中错误的屏幕截图:Xcode Error Screenshot
是否有其他人看到此问题并/或找到解决方案?
发布于 2019-12-27 09:38:40
由于GeoFire显然没有按您希望的方式对纬度和经度进行限制,因此您有两种选择
我建议使用第二种方法,因为您希望/需要显示您在UI中裁剪/限制了范围。
https://stackoverflow.com/questions/59494688
复制相似问题