I've been reading Geofire documentation but for some reason, I cannot save the location. I'm trying to save the locations after login. I debugged it and observed that it doesn't even get into the if error
. It also doesn't get latitude and longitude
coordinates.
Am I missing something? Thank you
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()
}
}
}