使用Swift

时间:2016-10-09 17:38:40

标签: ios swift firebase firebase-realtime-database geofire

我正在使用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)")
                }
            })

        }
    })
}

firebase console

1 个答案:

答案 0 :(得分:1)

Geofire旨在将地理位置数据与其他对象数据分开。 API不允许混合它们。

要将商品的位置信息与该商品的其他信息相匹配,请将它们存储在相同的商品下

Orders
  <orderId>
OrderLocations (or whatever key you prefer, as long as it is separate)
  <orderId>