Closed 24dev closed 6 years ago
That seems odd, and there are test in place for just this sort of issue. Could you provide a working (broken) example?
@MichaelSolati Haven't got anything live, but what extra info would you like to see?
This is my collection:
After making the request as shown above, I get this response:
+++++
This is my firebase config, if useful:
firebase.initializeApp(firebaseConfig);
firebase.firestore().settings({ timestampsInSnapshots: true });
const db = firebase.firestore();
const geostoreRef = db.collection('exploreMap');
// Create a GeoFirestore index
const geoFirestore = new GeoFirestore(geostoreRef);
In all sincerity a broken app would be helpful. I'm doing tests and fixes right now for other issues and have not seen this issue. So an example would be preferred. It can be simple, it just need to be broken.
Ok, so I just took a better look at your code, and I feel really silly not to have realized this before, but I do not think you are using the library correctly. In fact I'm surprised you're getting anything at all the way you are using it.
The below code creates a GeoFirestoreQuery:
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(51.5074, 0.1278),
radius: 5,
});
If you wanted to make a geoquery you'd use the on
listener for the key_entered
event which will return documents in your query, see here.
However you're calling the query
function, which returns a Firestore Query, or CollectionReference (depending on if you passed in a query function when you created or updated the query criteria).
Calling get
on this query
BYPASSES all of the GeoFirestore magic goodness, and would not provide you with what you want or expect... Instead you'd want to do something like this.
// Store all results from geoqueries here
let results = [];
// Create geoquery
const geoQuery = geoFirestore.query({
center: new firebase.firestore.GeoPoint(51.5074, 0.1278),
radius: 5,
});
// Remove documents when they fall out of the query
geoQuery.on('key_exited', ($key) => {
const index = results.findIndex((place) => place.$key === $key);
if (index >= 0) results.splice(index, 1);
});
// As documents come in, add the $key/id to them and push them into our results
geoQuery.on('key_entered', ($key, result) => {
result.$key = $key;
results.push(result);
});
I'll be closing this for now, as I think I have your issue/question addressed. However please let me know if I am mistaken and we can reopen this and go from there.
Brilliant, that fixed it. Sorry for my misunderstanding! The key_entered/exited is what confused me. Thanks for the great library!
i also had the same issue as @AlcuinGuest. finding this issue and explanation solved my dilemma as well. thank you for providing the info and great tools.
food for thought: when i read the docs i interpreted 'key_entered' and 'key_exited' as some type of keyboard events for a browser client-side scenario. i'm also fairly new to node.js. nonetheless, i was about to give up until i found this. thanks.
Trying to retrieve all the documents that fall within the radius of a certain point.
Query:
Firestore (documents set by geofirestore.set(): Document 1 (same as search point):
Document 2:
No matter what I try, it is always returning both results, even though they are 100's of kms away from eachother. Can someone please recommend what I can do to make this work?
Much appreciated! :)