Search code examples
javascriptfirebasegeofire

Firebase Geofire query only returns nearby items when a huge radius is set


For some reason my Geofire query only returns items if the radius is set to exactly 1197 or above. Any less and nothing will be returned. When the data is returned and I log the distances, they are all less than 1km, so this doesn't make any sense to me.

Any ideas for this one?

Code:

  this.firebaseRef = new Firebase("<my firebase - this is fine>");
  this.geoFire = new GeoFire(this.firebaseRef);

  this.geoQuery = this.geoFire.query({
    center: [50.72001, -1.8800],
    radius: 1197
  });

  this.geoQuery.on("key_entered", function(key, location, distance){
    console.log(key + ', ' + location + ', ' + distance);
  });

I should mention I'm using React, and this is in the componentWillMount method.

Thanks!

UPDATE: Geofire seems to require a Geohash to search the database, so to fix my issue I started to convert the lat/lng to geohashes and stored that too.


Solution

  • Geofire seems to require a Geohash to search the database and mine only stored the latitude and longitude, so to fix my issue I started to convert the lat/lng to geohashes and stored that too.

    To convert coordinates to a geohash, see https://github.com/chrisveness/latlon-geohash, this worked perfectly.