7
votes

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?

1
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. - Frank van Puffelen
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. - dramzy
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. - Frank van Puffelen
ref.child("posts").child(postID).addListenerForSingleValueEvent().... See firebase.com/docs/android/guide/… - Frank van Puffelen
Yes. But didn't we already cover that a few comments ago? - Frank van Puffelen

1 Answers

0
votes

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