1

I'm just trying to figure out a way to store user names and id's within a GeoFire node.

I want to save a location with GeoFire (using setLocation()) and I also want to save user credentials with it. I find it difficult since if I try storing something within a GeoFire node, it won't work well with GeoQueries. And if I try storing user credentials in FireBase, it will save in two separate nodes.

I've tried doing it where I make the key, of the GeoFire node, contain the username and userId and from there I can process that string and break it up to what I need. I'm not sure if this is an efficient method but it works. I just want to know if there's another way of doing this.

SaltySea
  • 700
  • 1
  • 7
  • 21
  • GeoFire separates the location data from other data for good reason. It does not support storing other data with the location data. See http://stackoverflow.com/questions/38340949/how-to-save-geofire-coordinates-along-with-other-items-in-firebase-database – Frank van Puffelen Aug 22 '16 at 03:55
  • Is there a way to sync the two pieces of data (location and other) together? Or should I just set the user data inside the key of my location data? i.e. gFire.setLocation("Username and other data here", myLocation); – SaltySea Aug 23 '16 at 21:25
  • You would usually keep the non-geo data under the same key in some other part of your JSON tree. E.g. `/users/$uid` for users. – Frank van Puffelen Aug 23 '16 at 23:07
  • Wait, so if I set the geo data key to the user's id, and I have a separate node for non-geo data where it also stores the user's id, I can bring the two together? So if I had a user setLocation near me and (with a GeoQuery) onKeyEntered I could bring up the user's data from the geo data they just set? – SaltySea Aug 24 '16 at 01:17
  • 1
    Yup. That's the whole logic of GeoFire. When a key enters your query, you [load/sync the associated data with a regular Firebase listener](https://firebase.google.com/docs/database/android/retrieve-data). – Frank van Puffelen Aug 24 '16 at 01:44
  • Oh! I think this will solve my problems then :) Thank you so much again, Frank – SaltySea Aug 24 '16 at 02:09

0 Answers0