0

Problem

You have a food delivery app where you need show a user a list of restaurants that'll deliver food to it's house.

Constraints

  1. Each restaurant has a potentially different delivery radius.
  2. Your restaurant database is Firebase's Firestore.

Keep in mind

  1. This is a web-based project and I'm using Firebase's frontend JavaScript library. However, if you feel like you can answer the question in an abstract way or with a different implementation please go ahead.
  2. I'm not interested in a real-time implementation, just a simple one-off listing of restaurants that fit the criteria.
  3. I'm familiar with using geohashes to query nearby points using geofirestore-js or geofirex. There are a few StackOverflow questions about that. However, this is not what I'm asking, as delivery radius of each queried point needs to be taken into account. It doesn't matter how close the restaurants are to the user, just if their delivery radius covers its location.
  4. Any geohash implementation should provide a solution for dealing with it's edge cases.

Example

enter image description here

We have 3 restaurants, A, B, and C. These are stored in our Firestore database as a document containing position (lat/lng, geohash, both, whatever you choose) and delivery radius in km (though unit is not important).

We also have the user's current position, in our delivery app's client client.

You'll notice that restaurant C is the closest one to our user yet it's the only one that doesn't deliver to our user's location. Therefore, our query should only return restaurants A and B.

So, my question is:

  1. How do you query all points whose radius contains another point in Firebase's Firestore?

Or, in this scenario:

  1. How do you query all restaurants whose delivery radius contains our user's location in Firebase's Firestore?

I'm sure there are better ways to put this, but this is as far as my knowledge on the subject has taken me. Thanks in advance.


Icons made by Smashicons from www.flaticon.com

Icons made by Freepik from www.flaticon.com
e5y
  • 13
  • 1
  • 5
  • Another user needed something similar yesterday, and came up with a solution/workaround based on GeoFirestore and storing multiple geohashes per document: https://stackoverflow.com/a/61144168. I'd also read my answer and the video linked from there, as they're likely a good introduction to why your requirement is actually quite hard to implement. – Frank van Puffelen Apr 11 '20 at 21:42
  • Hi Frank, will definitely watch your talk. I've thought of something similar to what the user answered, along the lines of saving the restaurant "point" (geohash) and 4 other points (define a rectangle around the restaurant as an aproximation to the delivery radius) but have zero clue how to implement it. I'd love to use a geo-library but most examples I could find center around "near me" queries without a clear path towards a solution for my question. I realize I'm obviously out of my depth here, that's why I was hoping for a complete answer to what I consider is a common problem. – e5y Apr 11 '20 at 22:36

0 Answers0