Home > Net >  The best way to query by location in firestore
The best way to query by location in firestore

Time:05-17

I am using Firebase 8.10.0 with Vue js 2.6.14

I am trying to query in Firestore about the documents that are less than 3 km away from my location And discovered that I could not do this query in firestore, I was frankly disappointed Then after watching a video by Frank van Puffelen on YouTube enter image description here

So the query here is to return all documents within the gray circle. But in order to get those documents, we need to query all four colored ranges of geohashes.

If you have a relatively uniform distribution of the documents, you might end up with this:

enter image description here

Each pin in this image is a document that is read by Firestore, but only the green pins are documents that fall within the range you actually wanted.

In my experiments, for a uniform distribution of documents, you end up reading between 2x and 10x more documents than needed with this approach. If this overreading is a cost concern for you, consider using the Realtime Database and its geofire library for your geoqueries. While the overreading will be the same, the billing structure is based on bandwidth and the amount of bandwidth consumed by the geoindex is pretty minimal there.

  • Related