Jacobo Koenig Jacobo Koenig - 5 months ago 234
Java Question

Using GeoFire with Firebase on Android, but can't find the DatabaseReference Class

I am trying to connect to my Firebase account and make a query using a specific location to see if there are any GeoFire positions in it. For this I am using the official tutorials, but haven't been able to create a Geofire object. Here is what the Tutorial says:

A GeoFire object is used to read and write geo location data to your
Firebase database and to create queries. To create a new GeoFire
instance you need to attach it to a Firebase database reference.

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("path/to/geofire");
GeoFire geoFire = new GeoFire(ref);

Following this tutorial, I run into the problem that Android Studio cannot resolve DatabaseReference symbol.

If I try to pass the Firebase object itself:

Firebase mLocs = new Firebase("https://example.firebaseio.com/Locations");
GeoFire geoFire = new GeoFire(mLocs);

I get an error saying that

com.google.firebase.database.DatabaseReference cannot be converted to

My Firebase object was appropriately instantiated and its context declared.


Any ideas what might be going wrong?


The tutorial is using the old Firebase SDK.

Follow this guide on how to setup the new Firebase SDK and then add the realtime database feature.

So, you will add these dependencies in the build.gradle file


Then, you can create GeoFire instance using the guide from GeoFire for Android github page