0

我一直在阅读 Geofire 文档,但由于某种原因,我无法保存该位置。我正在尝试在登录后保存位置。我调试它并观察到它甚至没有进入if error. 它也没有得到纬度和经度坐标。

我错过了什么吗?谢谢

var geoFireRef: DatabaseReference!
var geoRef: GeoFire!

override func viewDidLoad() {
    super.viewDidLoad()
    setUpElements()

    configureLocationManage()
    geoFireRef = Database.database().reference()
    geoRef = GeoFire(firebaseRef: geoFireRef)
}

@IBAction func loginButtonTapped(_ sender: Any) {

    // clean fields

    let email = emailTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)
    let pass = passwordTextField.text!.trimmingCharacters(in: .whitespacesAndNewlines)



    Auth.auth().signIn(withEmail: email, password: pass){
        (result,error) in
        if error != nil{
            self.labelError.text = error!.localizedDescription
            self.labelError.alpha=1
        }else {

            //GEOFire
           let userLat = UserDefaults.standard.double(forKey: "current_latitude")
           let userLong  = UserDefaults.standard.double(forKey: "current_longitude")

            let location:CLLocation = CLLocation(latitude: CLLocationDegrees(userLat), longitude: CLLocationDegrees(userLong))

           self.geoRef?.setLocation(location, forKey: Auth.auth().currentUser!.uid){ (error) in
           if (error != nil) {
             print("An error occured: \(error)")
           } else {
             print("Saved location successfully!")
           }

            }




            let homeViewController = self.storyboard?.instantiateViewController(identifier: constants.Storyboard.homeViewController) as? HomeViewController
            self.view.window?.rootViewController = homeViewController
            self.view.window?.makeKeyAndVisible()
        }

    }
}
4

1 回答 1

0

来自iOS 版 GeoFire

geoFire.setLocation(CLLocation(latitude: 37.7853889, longitude: -122.4056973), forKey: "firebase-hq") { (error) in
  if (error != nil) {
    print("An error occured: \(error)")
  } else {
    print("Saved location successfully!")
  }
}

不要忘记用你的价值观替换latitude和。forKey让我知道这是否适合您。

于 2020-06-08T08:58:35.623 回答