我如何在Geofire,Firebase中将用户吸引到我的位置附近 [英] How can i get user nearby my location in geofire,Firebase

查看:77
本文介绍了我如何在Geofire,Firebase中将用户吸引到我的位置附近的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此代码,我从Geolocs中仅获取一个值,仅是键和位置,而不是附近的位置.

With this code, I am getting only one value from Geolocs just key and location, not a nearby location.What is wrong with it

var geoFireRef: DatabaseReference?
    var geoFire: GeoFire?
    var myQuery: GFQuery?


func Geofire() {

        geoFireRef = Database.database().reference().child("Geolocs")
    geoFire = GeoFire(firebaseRef: geoFireRef!)
        self.geoFire?.setLocation(currentLocation!, forKey:Auth.auth().currentUser!.uid)

    myQuery = geoFire?.query(at: currentLocation!, withRadius: 100)

    myQuery?.observe(.keyEntered, with: { (key, location) in


        if key != Auth.auth().currentUser?.uid
        {
            let ref = Database.database().reference().child("Users").child(key)

            ref.observeSingleEvent(of: .value, with: { (snapshot) in
                let id = snapshot.key
            })

        }

    })

}

推荐答案

将GeoFire位置与所有内容分开,并带有引用其他附加数据的键,例如用户信息或帖子信息.由于混合使用静态和动态数据并不是存储数据的最有效方法.

Keep your GeoFire Locations separate from everything with a key to reference the other additional data e.g. user info or post info. As mixing static and dynamic data would not be the most efficient way of storing the data.

在这里查看我的数据结构并查询:

See my data structure and query here:

在Swift的Radius中从GeoFire检索密钥

这篇关于我如何在Geofire,Firebase中将用户吸引到我的位置附近的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆