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

1

-2

enter image description hereWith 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
            })

        }

    })

}
Abbotson answered 29/7, 2018 at 2:1 Comment(3)
The question is a bit unclear and there's not enough data to really understand the issue; reference your class vars consistently (self.geoFire and geoFire) and I am not sure there's a reason they are not just let statements as in let geoFireRef = ..., currentLocation is not defined so we don't know what that is, don't store coordinates in the users node as that's what the geolocs node is for. Also, check out both answers to this questionBiysk
Oh, and by your screenshot you only have one location for a user and that's this (Admin) user. If there is more data you should probably include it as TEXT please, no screenshots. Please do not include images in your questions. Include code and structures as text. To get your Firebase structure, use the Firebase console->Export JSON and copy an paste a snippet of your structure. See images and links are evilBiysk
Your first comment's link help me a lot to understand the actual problem I'm facing thanksAbbotson
B
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

Borowski answered 29/7, 2018 at 2:7 Comment(3)
I didn't get your point. Your means I have a set location separately and make query in other function/class???Abbotson
Yes. Add your location with a key of .uid which you are doing. But keep all other information about the user separate. then when you run a query all you will get are a bunch of keys, then you can reference them all and get the additional information.Borowski
I do but I didn't get , I am getting only one key that is my current userid and I set it in GeolocsAbbotson

© 2022 - 2024 — McMap. All rights reserved.