Home > Enterprise >  Read collection in Firestore to get GEO data
Read collection in Firestore to get GEO data

Time:01-12

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"?

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

CodePudding user response:

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 { /* ... /* }
  • Related