微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在随机firebase id swift 4下保存geoFire位置

我正在尝试在每个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!)

Post and UID node

解决方法

如果要将地理位置存储在相同的密钥下

let ref = userPostRef.childByAutoId()

您可以从ref获取密钥属性.所以:

geoFire?.setLocation(CLLocation(latitude: geoLatitude,forKey: ref.key)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐