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

How to get a query response without any event on GeoFire? #239

Open
bsgies opened this issue May 17, 2022 · 0 comments
Open

How to get a query response without any event on GeoFire? #239

bsgies opened this issue May 17, 2022 · 0 comments

Comments

@bsgies
Copy link

bsgies commented May 17, 2022

I'm using GeoFire to get the closest point from the center within a certain radius. I have shared my codebase below.

The issue I'm having is finding the closest point without any event. I have read the documentation which says:

There are five kinds of "key" events that can occur with a geo query:

Key Entered: The location of a key now matches the query criteria. Key Exited: The location of a key no longer matches the query criteria. Key Moved: The location of a key changed but the location still matches the query criteria. Query Ready: All current data has been loaded from the server and all initial events have been fired. Query Error: There was an error while performing this query, e.g. a violation of security rules.

I'm looking to query without any event. For example, I have point A at (51.59141592849507, 0.00877643935500006), point B at (51.593452498310185, 0.005547504234921514), and point C at (51.583411841367415, 0.007768887829733491).

What should I do if these points don't enter, exit, or move to or from the center? I still need to know their distance from the center.

var admin = require("firebase-admin");
var geofire = require('geofire');

// Fetch the service account key JSON file contents
var serviceAccount = require("service-account.json");

// Initialize the app with a service account, granting admin privileges
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  // The database URL depends on the location of the database
  databaseURL: "https://cnf-terseel-05-default-rtdb.firebaseio.com"
});

var db = admin.database();
var ref = db.ref("partners_location");

var ref2 = new geofire.GeoFire(ref);

var geoQuery = ref2.query({
 center: [-16.080257, 153.605347],
 radius: 8
});
geoQuery.on("key_entered", function(key, location, distance) {
 console.log(key, location, distance);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant