0

I'm using Geofire to store items with their location.

In order to retrieve items within a specific area I use Geofire's geo query:

 var queryHandle = query.observeEventType(.KeyEntered, withBlock: {(key: String!, location: CLLocation!) in
  println("Key '\(key)' entered the search area and is at location '\(location)'")
 })

The result is, as expected, keys in the specified area - my question is: how do I get the actual object so I can access the rest of the properties it has?

I'm doing all that as part of a UITableView because I want to present objects near me in a table (and later on on a map)

Any best practices in populating a UITableView using geofire will be appreciated as well.

Thank you!

Doron Goldberg
  • 643
  • 1
  • 9
  • 23
  • Typically with a loop of https://firebase.google.com/docs/database/ios/retrieve-data#read_data_once. Read my answer here on why that is not as slow as you may thing: http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen May 26 '16 at 19:29

1 Answers1

0

You can simply create a value single event and read the value. Firebase is fast and efficient enough to read it and this will work just fine with UITableViews and with UICollectionViews with no problem at all.


    //ref is the reference to your object's parent path, and key is the value you received with the geofire query
    ref.childByAppendingPath(key).observeSingleEventOfType(.Value, withBlock: {       
       (snapshot:FDataSnapshot!) in

        //The snapshot has the data of your actual object        

    })
Ymmanuel
  • 2,523
  • 13
  • 12