Git Product home page Git Product logo

Comments (6)

MichaelSolati avatar MichaelSolati commented on July 16, 2024 1

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.

24dev avatar 24dev commented on July 16, 2024 1

Brilliant, that fixed it. Sorry for my misunderstanding! The key_entered/exited is what confused me. Thanks for the great library!

from geofirestore-js.

MichaelSolati avatar MichaelSolati commented on July 16, 2024

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.

24dev avatar 24dev commented on July 16, 2024

@MichaelSolati Haven't got anything live, but what extra info would you like to see?

This is my collection:

screen shot 2018-10-09 at 17 59 51

After making the request as shown above, I get this response:

screen shot 2018-10-09 at 18 02 58

+++++

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.

MichaelSolati avatar MichaelSolati commented on July 16, 2024

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.

stevenyix avatar stevenyix commented on July 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.