UPDATE
I have been trying to read through all the docs (of firebase and geofire) and searching on the web and I am having issues trying to grasp how to run a query using geofire and populating a uitableview with the data queried.
I have read about the different implementations of populating a table from this post, but I am having trouble understanding how to create either a .Value query or .ChildAdded query properly with the strings(of keys) that the geofire query generates.
Hopefully someone could help me out with some sample code and we can leave it up to help future visitors with similar issues.
Any help would be appreciated! Thanks in advance!
ORIGINAL QUESTION
I am trying to run a query using Firebase using the Geofire add-on and trying to pull a list of posts based on where the user's location as the center. It does work but the tableview is only being filled with one result(which is the the current or latest post). How do I run a geoquery with the user's location to pull ALL the posts that are around them?
Here is my code for reference:
if(userLocation != nil){
print("geoQuery ran")
let geoFire = GeoFire(firebaseRef: Firebase(url: "https://myfirebase.firebaseio.com/PostLocation"))
let center = CLLocation(latitude: self.userLocation!.latitude, longitude: self.userLocation!.longitude)
let circleQuery = geoFire.queryAtLocation(center, withRadius: 6)
circleQuery.observeEventType(GFEventTypeKeyEntered, withBlock: {
(key: String!, location: CLLocation!) in
print("Key '\(key)' entered the search area and is at location '\(location)'")
let ref = Firebase(url:"https://myfirebase.firebaseio.com/Posts")
ref.queryOrderedByChild("objectID").queryEqualToValue(key)
.observeEventType(.Value, withBlock: { snapshot in
var tempItems = [NSDictionary]()
for item in snapshot.children {
let child = item as! FDataSnapshot
let dict = child.value as! NSDictionary
tempItems.append(dict)
}
self.items = tempItems
self.tableView.reloadData()
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
print(snapshot.value.objectForKey("text"))
print(snapshot.value.objectForKey("user"))
})
})
Thanks in advance!