Captai-N
Captai-N

Reputation: 1534

Read collection in Firestore to get GEO data

I'm trying to read a collection group in Firestore to get the GEO data. My path looks like this. How do I get all documents and thus all GEO data that are in "Houses" collection?

Activity:

val ref = FirebaseDatabase.getInstance().getReference("/Houses")
val geoFire = GeoFire(ref)

val geoQuery: GeoQuery = geoFire.queryAtLocation(GeoLocation(37.7832, -122.4056), 0.6)

Path in Firestore:

/User/[email protected]/Houses/randomDoc

enter image description here

Upvotes: 0

Views: 44

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 1

The following line of code creates a reference that points to the Houses node in the Realtime Database:

val ref = FirebaseDatabase.getInstance().getReference("/Houses")

On the other hand, your screenshot shows a Firestore database. While both databases are a part of Firebase products, both are different databases with different mechanisms. So to create a CollectionReference that points to the Houses sub-collection, you have to use the following lines of code:

val email = Firebase.auth.currentUser?.email
val db = Firebase.firestore
val housesRef = db.collection("User").document(email).collection("Houses")
housesRef.get().addOnCompleteListener { /* ... /* }

Upvotes: 1

Related Questions