1

I am building a mobile app that uses Firebase services for the backend (Firestore, functions, etc).

Currently I store the latest best available geolocation (longitude, latitude) for every user in Firestore. What I'd like to do is to query Firestore to show users other users that are in the area (in addition to some other filters like age range).

How could I best do this? I tried to find anything regarding Firestore being able to query geolocation distances, but could not find anything. Does this mean I need to do these calculations on the client side?

It seems a bit much to query all the users (that could be anywhere in the world) and filter these client-side, or even in a cloud function.

Another thing that make it harder is that Firestore supports only one range field, so even if I were able to do some high level filter for geolocation (and doing the fine grained filters client-side), then it still means I can't use any other range filters in the query.

How do other applications approach this issue?

Thanks in advance for any pointers!

Joni
  • 831
  • 7
  • 23
  • What if you used the user's current position to calculate the maximum/minimum latitude and longitude (for the desired area radius) and used that on separate queries? You'd still need a couple of queries, but it might prove less resource-intensive than calculating distance for everyone. – Gabriel Lovetro Jul 05 '18 at 14:12
  • There is no support yet for native geoqueries on Firestore. See https://stackoverflow.com/questions/46553682/is-there-a-way-to-use-geofire-with-firestore (and more from [this list](https://www.google.com/search?q=firestore+geoquery). If you want to see how you can already do this today, you can calculate a geohash for each lat/lon, and query on those. Have a look at a talk I recently gave on this precise topic: https://www.youtube.com/watch?v=mx1mMdHBi5Q and to this jsbin showing code+results: https://jsbin.com/mosiza/44/edit?js – Frank van Puffelen Jul 05 '18 at 14:13
  • Thanks @FrankvanPuffelen I'll watch the video! – Joni Jul 05 '18 at 14:59
  • 1
    @GabrielLovetro Thanks for your comment! – Joni Jul 05 '18 at 15:00

0 Answers0