How To Filter Firestore Collection Data Using Function (for Location Distance Filtering)
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:
- Some developers have ported Firebase's GeoFire library to Firestore. See How to run a geo "nearby" query with firestore?,
- I gave a talk about this a while ago, which is available on youtube: https://www.youtube.com/watch?v=mx1mMdHBi5Q
- AngularFirebase.com also has a page on Realtime GeoQueries With Firestore
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)"