Beezebrown
Beezebrown

Reputation: 45

Geofire-js: Return all key's whose instantaneous location matches geoQuery

I’m working with Firebase on a project, and I’m having trouble wrapping my head around how the querying works. I’m trying to query and find any other user’s that are within a certain radius of the current user’s location.

I’m able to create the the geoQuery, but I’m not sure how to return the user's whose locations are within the radius.

From the examples, it seems that key_entered is only triggered when a location in the DB changes. All my location’s are all static once set, so I just want to do a query, then return all the user’s whose instantaneous location falls within the queries radius.

Is this possible with Geofire?

My location information is saved in Firebase like this:

users {
   uid: {
        location: {
          g: 'GeoHash',
          l: [lat, long]
         }
      }
   }

Here's my Query:

let geoQuery = geoFire.query({
                center: [currentUser.location.l[0], currentUser.location.l[1]],
                radius: 1000
            });

Upvotes: 0

Views: 686

Answers (1)

Beezebrown
Beezebrown

Reputation: 45

The issue was that I hadn't be storing the locations using geoFire's set method, so the geoHash was never created, giving geoFire nothing to query off of. Thanks for the help @jacob!

Upvotes: 0

Related Questions