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
- Each restaurant has a potentially different delivery radius.
- Your restaurant database is Firebase's Firestore.
Keep in mind
- 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.
- I'm not interested in a real-time implementation, just a simple one-off listing of restaurants that fit the criteria.
- 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.
- Any geohash implementation should provide a solution for dealing with it's edge cases.
Example
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:
- How do you query all points whose radius contains another point in Firebase's Firestore?
Or, in this scenario:
- 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