Skip to content Skip to sidebar Skip to footer

How To Filter Firestore Collection Data Using Function (for Location Distance Filtering)

Would like to know how to filter a Firestore collection of docs using a function where some of the function args are the values of the collection documents. Suppose had some Firest

Solution 1:

There is no way to pass a function into Cloud Firestore that it then uses to filter the documents that it returns. You either need to pass in static values (e.g. the latitude and longitude you want back), or you will need to read all documents and filter with the function client-side.

What you're trying to do is known as a geoquery: returning documents based on their distance to a known point. Unfortunately that functionality is not built into Cloud Firestore yet, even though it has support for a geographical point data type. It is possible to build it yourself, though you should realize such queries are quite inefficient at the moment.

To learn more about this:

Solution 2:

So as answered previously, Firestore doesn't support native geo queries. This is a bit of a shameful plug for some open source stuff I've been working on...

https://github.com/mbramwell1/GeoFire-Android

That lets you do standard Firestore queries, but also adds in the ability to search by location aswell. Give it a look over it may do what you want.

Post a Comment for "How To Filter Firestore Collection Data Using Function (for Location Distance Filtering)"