Closed apobbati closed 9 years ago
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)");
});
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?
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?
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.
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.
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.