0

I have GeoPoints stored as location in firestore within users collection.

Using my current GeoPoint, I need to get documents/users around me based on a given distance. As an example I need to get users around me within 100km.

I searched on stackoverflow and realized there are only few GeoPoint based firestore questions. According to those I constructed a query similar to below,

function getUsers(lower, upper) {
  let db = admin.firestore();
  var usersRef = db.collection('users')
    .where('location', isGreaterThan, lower)
    .where('location', isLessThan, upper);

  var users = usersRef.get();
  return users;
}

But my question is,

How can I construct "lower" and "upper" GeoPoints based on a given distance?

Im bit confused here as GeoPoints consist of Longitude and Latitude which represent a point in the map. Having two points (lower, upper) in the map, is it possible to get a bounding circle with a radius of 100km?

Also please give your suggestions if you have better solutions to achieve this using GeoPoint in firestore. Can't we pass my current GeoPoint and a radius value which ultimately gives documents around that circle?

channae
  • 951
  • 1
  • 12
  • 28
  • Check [this](https://stackoverflow.com/questions/46553682/is-there-a-way-to-use-geofire-with-firestore) out. – Alex Mamo Oct 02 '18 at 11:16
  • @AlexMamo This solution seems promising. But does this requires to alter my firebase structure? Right now I'm storing document ref key as userId. – channae Oct 02 '18 at 11:47
  • I haven't tried it yet. Hope it doesn't require to alter your firebase structure. – Alex Mamo Oct 02 '18 at 11:50
  • If you'd like to learn exactly how to do that, see my talk here: https://www.youtube.com/watch?v=mx1mMdHBi5Q or Jeff's much shorter tutorial here: https://www.youtube.com/watch?v=lO1S-FAcZU8 – Frank van Puffelen Oct 02 '18 at 15:33

0 Answers0