How can i get user nearby my location in geofire,Firebase

只愿长相守 提交于 2019-12-08 13:57:39

问题


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
            })

        }

    })

}

回答1:


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:

Retrieving Keys From GeoFire within Radius in Swift



来源:https://stackoverflow.com/questions/51576643/how-can-i-get-user-nearby-my-location-in-geofire-firebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!