Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to query once for a given location and radius? #73

Closed
apobbati opened this issue Sep 17, 2015 · 5 comments
Closed

Is there a way to query once for a given location and radius? #73

apobbati opened this issue Sep 17, 2015 · 5 comments

Comments

@apobbati
Copy link

Is there a way to query once for a given location and radius? I don't want to get changes realtime in this use-case. Instead, I just need all the results once the query completes.

I'm looking for something similar to the once function in Firebase.

@jwngr
Copy link

jwngr commented Sep 17, 2015

Yeah, you can do this using the "ready" event listener. It would look something like this:

geoQuery.on("ready", function() {
  // This will fire once the initial data is loaded, so now we can cancel the "key_entered" event listener
  onKeyEnteredRegistration.cancel();
});

var onKeyEnteredRegistration = geoQuery.on("key_entered", function(key, location, distance) {
  console.log(key + " entered query at " + location + " (" + distance + " km from center)");
});

@jwngr jwngr closed this as completed Sep 17, 2015
@rcubarocha
Copy link

The Ready Event tells you when the initial data is loaded, sure, but what he's asking is if there is any way to just get all the data for the matching keys in one swoop instead of listening for individual events for each one.

As things are I can either query Firebase for the actual object for each key returned by Geofire on every Key Entered Event or I can pool the keys until the Ready Event fires and then I make a query to Firebase for the objects of all the keys returned by Geofire.

Both approaches seem cumbersome in their own ways.

Is there another way of doing this?

@jwngr
Copy link

jwngr commented Sep 17, 2015

I still think I answered the initial question and you have a different question. You want to grab data stored outside of GeoFire, elsewhere in your Firebase database, right? If that is the case, then you should just look them up using one of the two methods you suggested. Both of your suggested ways of doing the looks should be only a few lines of code. Plus, Firebase uses a persistent websocket connection which should make this really quick as we won't continuously be re-establishing HTTPS connections. What exactly is cumbersome about this method? Also, is this really a problem with just the initial data or do you want a way to look up the connected data even in the realtime use case?

@rcubarocha
Copy link

Thanks for the quick reply.

I guess when I say cumbersome I just mean it seems 'more than necessary.' I suppose to me it all comes down to why the GeoFire query only returns keys and not objects?

Rarely is a key by itself of any use, so having to add another step to get the actual object seems unusual to me. But I do agree it is not hard or anything, just seems somewhat unnecessary.

@jwngr
Copy link

jwngr commented Sep 17, 2015

I totally get where you are coming from and this has been suggested before. I unfortunately can't find the previous thread right now with my full answer (was it on GitHub, our Google Group, my email inbox, who knows?!). If and when I do, I'll post it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants