3

I am trying to integrate Geofire into a Firebase Objective-C app, but I'm not sure how to set up the Geofire node to observe my Firebase storage base. Here is what the Geofire start-up guide advises:

"To create a new GeoFire instance you need to attach it to a Firebase database reference"

My question is: What does it mean to "attach it to a Firebase database reference"?

In my code I would like Geofire to observe this Firebase location:

@"https://myApp.firebaseio.com/ios/languages"

Here is what the "languages" node looks like in Firebase:

languages
--Arabic
----FakeUser1
------latitude: "38.8438"
------longitude: "-77.62432"
----FakeUser2
------latitude: "38.6438"
------longitude: "-77.32432"
--English
----FakeUser1
------latitude: "38.3438"
------longitude: "-77.92432"
----FakeUser2
------latitude: "38.2438"
------longitude: "-77.02432"

What I'd like to know is how to get Geofire to observe and store the locations of each fake user. Do I create a unique Geofire node and read users into it whenever I read users into the /languages/arabic or /languages/english references? Or will Geofire observe the pre-existing node--ie. will something like this do the trick:

Firebase *geofireRef = [[Firebase alloc] initWithUrl:@"https://myApp.firebaseio.com/ios/languages"];
GeoFire *geoFire = [[GeoFire alloc] initWithFirebaseRef:geofireRef];
Philip Sopher
  • 627
  • 2
  • 8
  • 19

2 Answers2

2

I figured it out. You create a unique Geofire node that mirrors the one you're trying to monitor.

Philip Sopher
  • 627
  • 2
  • 8
  • 19
0

I use this structure, which seems to work well.

app-id
-> geodata
--> geofire
---> key
----> g: <geohash>
-----> l: 
-------> 0: Lat
-------> 1: Lon

--> other
---> key
----> <otherhash object>

When you save data you will separately save the geofire data using:

mDatabase = FirebaseDatabase.getInstance().getReference("geodata");      

geoFire = new GeoFire(mDatabase.child("geofire"));

geoFire.setLocation(people.key, new GeoLocation(people.Lat, people.Lon));

Then you would separately save your data in firebase:

    mDatabase = FirebaseDatabase.getInstance().getReference("geodata");

    mDatabase.child("other").child(people.key).setValue(people);

People is my custom class object which will be serialised in firebase with the same key.

Hope this helps. :)

philshem
  • 24,761
  • 8
  • 61
  • 127
pvella
  • 190
  • 1
  • 9