Associate Geofire location with Firebase entry
Asked Answered
W

1

7

So, I have an Android app that lets users view posts within a certain radius of their current location. I am storing the posts using firebase, but I couldn't find a way to query for posts within a specific radius in firebase, so now I am thinking of using geofire, but I am not sure if there is a way to store a location alongside my firebase posts using geofire, so, it would seem to me like the only way to associate a location with a post is to have the post id (the one generated by firebase) be the key for the geofire location. Is this correct or is there a better way?

Wyn answered 24/11, 2015 at 4:55 Comment(9)
Sounds about right. Most implementations keep the properties of the posts separate from the geodata, so that the geoqueries only deal with minimal data. See geofire.firebaseapp.com for an introduction.Happiness
Ok, so two queries would be required to retrieve the posts here. One using Geofire to find locations within a certain radius of the current location and retrieve their keys and another using Firebase to retrieve post info for all posts that match the IDs from the Geofire locations, correct? I was hoping to use one query, but it seems it'll have to be this way.Wyn
The second one isn't strictly speaking a query. It's a direct lookup by ID. Given that Firebase works over an existing socket connection and you can pipeline them, these lookups are pretty fast. If not: start a new question with the code that is problematic and we can have a look.Happiness
Once I get the post IDs, how do I retrieve the post details in firebase? I am new to firebase and the documentation doesn't seem to show a straightforward way of doing this. I should probably ask this as a separate question, but it might be trivial.Wyn
ref.child("posts").child(postID).addListenerForSingleValueEvent().... See firebase.com/docs/android/guide/…Happiness
Does that mean I am making a call for each post I need to retrieve?Wyn
Yes. But didn't we already cover that a few comments ago?Happiness
Well, we covered that a query and then a lookup are required to get post details based on current location, but I didn't realize that we need a lookup per post. I guess that's fine if they don't take too long.Wyn
Firebase geofire-js : how to get list of keys of near by static(fixed) locations : #43633246Mullane
M
0

Yes, that the correct way. You create a flat DB. One branch with post data and one branch with locations.

Mop answered 18/3, 2017 at 13:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.