【发布时间】:2020-06-07 05:58:45
【问题描述】:
我一直在阅读 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()
}
}
}
【问题讨论】:
-
这是干什么用的?
let userLat = UserDefaults.standard.double(forKey: "current_latitude")?在调用之前,您是否在 UserDefaults 中保存了一些内容? -
感谢您的回复。我对此很陌生,所以我认为我得到了默认的纬度和经度。我也尝试过直接发送值,但不是运气。
-
您在问如何让设备经纬度吗?或者你只是在拥有它后难以编写它? GeoFire Docs 涵盖了很多内容。
标签: swift firebase google-cloud-firestore geofire iosdeployment