MichaelSolati / geofirestore-js

Location-based querying and filtering using Firebase Firestore.
https://geofirestore.com
MIT License
505 stars 58 forks source link

Having trouble successfully querying my data #30

Closed MikeJWms closed 6 years ago

MikeJWms commented 6 years ago

Hi,

Sorry for the basic question, but I've been banging my head against this for the past few hours.

In the test app I set up, I have a function that adds 1000 randomly placed locations to my firestore collection within ~800km of the user: screen shot 2018-08-22 at 11 38 58 am

Then I set up a query using geoFirestore.query(), and pass in an object containing a center GeoPoint and radius. I use .query() to turn it into a firestore query object, then execute a .get(): screen shot 2018-08-22 at 11 39 17 am

What I get back though is all 1000 locations, so for some reason the query is not returning what it should. The entire test project can be found here, and the component where all the relevant code is here.

What am I doing wrong? Thanks for your help and all the hard work going into this project!

MichaelSolati commented 6 years ago

So the query object you get back is a modification on the collection based on the query you wrote (or just the collection if you didn't write a query function). So when you apply the get() the QuerySnapshot returned is based on YOUR query, not the additional magic sauce that geofirestore does (which is the location filtering). Point being, you're not doing anything wrong, it just doesn't do what you think it does.

Now the main reason why I couldn't modify it so you get your expected result is because when you query around a location geofirestore may run multiple queries (not just one). Geofirestore package wraps/scans hashes around the hash of what/where you select. That way if you're point is by the borderline of where a hash could be we don't miss areas right outside of the query. So if we're doing multiple queries in order to ensure that we have the full area you want searched we need to modify the base query you wrote with different hashes (so the returned query would not be what you expected/wanted).