我正在使用Geofire框架进行Firebase后端,我在保存数据库位置方面存在问题。
我需要的是按照自动生成的id值的顺序将用户选择的位置保存在Orders
表中。
@IBAction func proceedOrder(_ sender: UIButton){
FIRAuth.auth()?.addStateDidChangeListener({ (auth, user) in
if user != nil {
let userUID = (user?.uid)!
let scheduled = self.pickDateTextField.text!
let time = self.pickTimeTextField.text!
let service = self.pickServiceTextField.text!
let model = self.carModelTextField.text!
self.ref = FIRDatabase.database().reference(fromURL: "https://***-****-***.firebaseio.com/")
let geoFire = GeoFire(firebaseRef: self.ref)
let dateCreated = Int(NSDate().timeIntervalSince1970)
let orderRef = self.ref.child("Orders").childByAutoId()
let values = ["uid":userUID,"date_Created":dateCreated,"date_Scheduled":scheduled,"time_Scheduled":time,"service_Type":service,"car_Model":model,"status":"Scheduled"] as [String : Any]
orderRef.updateChildValues(values, withCompletionBlock: { (err, dbRef) in
if err != nil {
print("Error: \(err)")
return
} else {
geoFire?.setLocation(self.currentLocation, forKey: "Orders\(dbRef.key)")
}
})
}
})
}
答案 0 :(得分:1)
Geofire旨在将地理位置数据与其他对象数据分开。 API不允许混合它们。
要将商品的位置信息与该商品的其他信息相匹配,请将它们存储在相同的商品下
Orders
<orderId>
OrderLocations (or whatever key you prefer, as long as it is separate)
<orderId>