firebase / geofire-js

GeoFire for JavaScript - Realtime location queries with Firebase
MIT License
1.44k stars 345 forks source link

Is it possible to get list of objects in the area? #57

Closed Moonrise1275 closed 9 years ago

Moonrise1275 commented 9 years ago

with geofire? I mean existing objects. not a new/removed/moved one.

jwngr commented 9 years ago

Hey @Moonrise1275 - if I understand you correctly, you essentially just want to get all keys which are currently in an area and not listen for added/removed keys. You can do this using a combination of the "key_entered" and "ready" events:

var onReadyRegistration = geoQuery.on("ready", function() {
  console.log("GeoQuery has loaded and fired all other events for initial data");

  // Cancel the "key_entered" callback
  onKeyEnteredRegistration.cancel();
});

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