怎么样了?
我在Firebase中有以下数据结构:
reports
.XbCacF7tHosOZxxO(child generated by auto-id)
..userId: "XvSjDkLsaA8Se"
..message: "Text goes here"
..latitude: "30.123131"
..longitude: "50.3313131"
.Yoa7HsgTuWm97oP(child generated by auto-id)
..userId: "XvSjDkLsaA8Se"
..message: "Text goes here 2"
..latitude: "30.99999"
..longitude: "50.99999"
users
.XvSjDkLsaA8Se
..name: "John"
..email: "[email protected]"
该应用程序的想法是用户可以制作多个“报告”。
将来,如果我有数百个“报告”,我不希望它超出我的查询。所以我试图找到一种使用Geofire查询的方法。
我的问题是:有没有办法只使用Geofire的半径特征和“报告”的纬度和经度来获取我附近的“报告”?
谢谢!
我刚刚找到了一种方法。
我必须使用在创建报告时由Auto Id生成的相同ID来保存我的Geofire节点“reports_locations”。
我的应用在Firebase上保存数据的功能:
//Save data to Firebase Database
let key = report.childByAutoId().key
report.child(key).setValue(dataToSaveInFirebase)
//Save data to Geofire node
let userLocal = database.child("reports_locations")
let geoRef = GeoFire(firebaseRef: userLocal)
let location = CLLocation(latitude: self.localUser.latitude, longitude: self.localUser.longitude)
geoRef?.setLocation(location, forKey: key)
我希望它可以帮助其他人。