在随机firebase id swift 4下保存geoFire位置
发布时间:2020-12-14 04:32:31 所属栏目:百科 来源:网络整理
导读:我正在尝试在每个postId下保存地理位置信息,但目前还不太清楚如何这样做.有人可以帮我弄清楚如何在postId节点下保存信息. @objc func handlePost() { navigationItem.rightBarButtonItem?.isEnabled = false guard let uid = Auth.auth().currentUser?.uid e
我正在尝试在每个postId下保存地理位置信息,但目前还不太清楚如何这样做.有人可以帮我弄清楚如何在postId节点下保存信息.
@objc func handlePost() { navigationItem.rightBarButtonItem?.isEnabled = false guard let uid = Auth.auth().currentUser?.uid else { return } guard let caption = textView.text,caption.characters.count > 0 else { return } let userPostRef = Database.database().reference().child("posts").child(uid) let ref = userPostRef.childByAutoId() guard let locationName = locationNameButton.titleLabel?.text else { return } let latitude = lat let longitude = long let geoLatitude = (latitude as! NSString).doubleValue let geoLongitude = (longitude as! NSString).doubleValue geoFireRef = Database.database().reference().child("posts").child(uid) geoFire = GeoFire(firebaseRef: geoFireRef) let values = ["caption": caption,"locationName": locationName,"latitude": latitude,"longitude": longitude,"creationDate": Date().timeIntervalSince1970] as [String : Any] geoFire?.setLocation(CLLocation(latitude: geoLatitude,longitude: geoLongitude),forKey: ref.key!) 解决方法
如果要将地理位置存储在相同的密钥下
let ref = userPostRef.childByAutoId() 您可以从ref获取密钥属性.所以: geoFire?.setLocation(CLLocation(latitude: geoLatitude,forKey: ref.key) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |