GeoFire help

139 views
Skip to first unread message

Ross Leung

unread,
Dec 20, 2015, 1:00:22 AM12/20/15
to Firebase Google Group
Hi community,

I'm new to iOS development and I can't seem to get GeoFire working correctly. I read through the documentation but I can't seem to understand it correctly.

My app constantly monitors the user's location with CLLocation (I got that working correctly, the app is displaying the correct latitude and longitude information), and I have 2 locations in my database that is near the latitude/longitude. These two locations' latitude/longitude information is fed in from GeoFire setLocation() method and I can do that successfully too. My issue is I can't get queryAtLocation working correctly. I believe it has something to do with my data structure on Firebase, this is how it looks like (I faked the hash and latitude/longitude information here):

my_iOS_app:
  post:
    -K141KJSLF (first unique post IDs created by Firebase childByAutoID )
       -coordinates
          -g: "098salfj" (unique hash created by GeoFire)
          -l
             -0: 15.931309 (latitude populated by GeoFire)
             -1: 100.131234 (longitude populated by GeoFire)

    -K130AFE (first unique post IDs created by Firebase childByAutoID )
       -coordinates
          -g: "9had89j" (unique hash created by GeoFire)
          -l
             -0: 15.9413 (latitude populated by GeoFire)
             -1: 100.14131 (longitude populated by GeoFire)

So the GeoFire reference is GeoFire(firebaseRef: my_iOS_app/post). When I do the queryAtLocation with center coordinates very close to those two posts' coordinates, the query_handle is not returning anything. Is it because my firebaseRef is pointing at "post"? Is it because the GeoFire hash/coordinate information is embedded two layers below the GeoFire firebaseRef?

In the GeoFire example with the bar reviews, I think they also embed their coordinates 1-2 layers below the Firebase reference too...Any know what I did wrong? Thank you in advance!

Jonny Dimond

unread,
Dec 21, 2015, 1:26:59 PM12/21/15
to Firebase Google Group
Hi Ross,

the coordinates need to be on the top-level (so under the ID key, not under coordinates). The example in the blog post was an example of what to do when you need additional data with GeoFire. It basically says you need to keep two locations in Firebase in sync. One that is set and queried exclusively using GeoFire, and another where you are free to write your own data, however GeoFire will not be able to query the data. So in you example you would have my_iOS_app/post and my_iOS_app/geofire_post. While you can save the coordinates in the post (to easily display) you will also need to save them in geofire_post with the same key, so you can later look up that key in my_iOS_app/post.

Jonny
Reply all
Reply to author
Forward
0 new messages