firebase / geofire-js

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

GeoQuery #185

Closed MIdkhat closed 3 years ago

MIdkhat commented 5 years ago

I am learning how to work with GeoFire and started on a quite simple project - there is a bunch of locations, I want to make a query based on some point and radius. here is the code so far:

var geoFireRef = firebase.database().ref().child('locations');
var geoFire = new GeoFire(geoFireRef);

// Create a GeoQuery
var geoQuery = geoFire.query({
    center: [-37.81, 144.96],
    radius: 7
});

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

// Test get key location
geoFire.get("3").then(function(location) {
    if (location === null) {
    console.log("Provided key is not in GeoFire");
    }
    else {
    console.log("Provided key has a location of " + location);
    }
    }, function(error) {
    console.log("Error: " + error);
    });

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

The data structure is also very simple: image

Here is the response in the console: scripts.js:358 GeoQuery has loaded and fired all other events for initial data scripts.js:371 Provided key has a location of -37.8700135,144.7632183

I am certain there are a lot of points in my dataset which should fall into 7km circle, but I don't get any. Get request does provide location for given keys, so I presume the issue is in the way I handle the Query.

puf commented 3 years ago

That code looks correct at first glance. If the problem still persists, do you have a database somewhere with your data so that I can test against it?

MIdkhat commented 3 years ago

That code looks correct at first glance. If the problem still persists, do you have a database somewhere with your data so that I can test against it?

Thanks, I have sorted it out some time ago :)