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