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

        }

    })

}
  • 1
    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 question](https://stackoverflow.com/questions/42810068/using-geofire-queries-in-swift-does-not-give-useful-output/42811267#42811267) – Jay Jul 29 '18 at 16:41
  • 1
    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 evil](http://idownvotedbecau.se/imageofcode) – Jay Jul 29 '18 at 16:48
  • Your first comment's link help me a lot to understand the actual problem I'm facing thanks – jagdeep singh Jul 30 '18 at 02:29

1 Answers1

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

David Henry
  • 1,972
  • 20
  • 43
  • I didn't get your point. Your means I have a set location separately and make query in other function/class??? – jagdeep singh Jul 29 '18 at 02:13
  • 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. – David Henry Jul 29 '18 at 02:16
  • I do but I didn't get , I am getting only one key that is my current userid and I set it in Geolocs – jagdeep singh Jul 29 '18 at 02:37