0

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.

sherlock
  • 367
  • 5
  • 15
  • GeoFire provides methods for saving the lat/long that should create the geohash on your behalf. Those may be helpful. – Kato Oct 08 '15 at 16:50

1 Answers1

0

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.

sherlock
  • 367
  • 5
  • 15
  • Is it possible in Javascript? To search keys (list of keys) of near by static(fixed) locations - which are pre-added in firebase datastore. Note: not using 'key_entered' because 'key_entered' only fires when new or position updated. What about previously added locations but coming under given radius. How is it possible?? – Ankit Maheshwari Apr 26 '17 at 10:50
  • Yes, that's definitely possible using Geofire. I'd recommend looking at the documentation for that, I've not worked with Geofire for over year so can't remember how to do it. – sherlock Apr 26 '17 at 14:08
  • Nope, not found! Please check this question for details: http://stackoverflow.com/questions/43632746/firebase-geofire-js-how-to-get-list-of-keys-of-near-by-staticfixed-locations – Ankit Maheshwari Apr 27 '17 at 05:31