Comments (6)
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.
from geofirestore-js.
Brilliant, that fixed it. Sorry for my misunderstanding! The key_entered/exited is what confused me. Thanks for the great library!
from geofirestore-js.
That seems odd, and there are test in place for just this sort of issue. Could you provide a working (broken) example?
from geofirestore-js.
@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);
from geofirestore-js.
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.
from geofirestore-js.
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.
from geofirestore-js.
Related Issues (20)
- Question - how can I find near documents with each unique radius? HOT 11
- How to write to firestore after geofirestore query HOT 1
- can't write to firestore properly after geofirestore query HOT 1
- StartAt or startAfter support HOT 1
- Query speed HOT 6
- Custom document key HOT 1
- Geoqueries with additional queries? HOT 3
- When querying `near`: `distance` prop is missing when distance is 0 HOT 1
- Support for Firebase JS SDK 9 HOT 9
- customKey not working on read HOT 10
- Pass a custom document ID HOT 1
- Query returning zero results when filtering with where HOT 8
- Support for new firestore 9.x? HOT 1
- runTransaction on a collection (server-side using cloud functions) HOT 1
- firebase geofirestore v9 not working HOT 1
- Bug double removed on a marker HOT 1
- Geofirestore and onSnapshot are giving delayed events - information is not updating properly
- Unsubscribe from GeoQuery.onSnapshot on document deletion HOT 1
- Typescript errors when trying to deploy function HOT 2
- Is there a way to update the criteria of GeoQuery ? Rather then making a new one
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geofirestore-js.