skip to Main Content

I want to display nearby points stored in a database on a map. However, there are over 1000 points, and I am having trouble figuring out how to construct that data.

For example, if you search for "McDonald’s" using the Google Maps app, it will show nearby McDonald’s instead of showing you a McDonald’s 1000 km away.

I’m trying to use Firebase’s Cloud Firestore for my database, is this appropriate?
Do you think Cloud Firestore is not suitable for this because of the payment per document?

One of the data is like:

{
  "name": "1",
  "cord": {
    "lat": ....,
    "lon": ....,
  },
  "type": "pin",
  ....
}

2

Answers


  1. I’m not sure if Firebase Storage is suitable for that amount of data. Instead of using latitude and longitude, you might want to use geohashes. They can help you manage and search your location data more easily as well as storing less data, and reducing the costs.

    Login or Signup to reply.
  2. However, there are over 1000 points, and I am having trouble figuring out how to construct that data.

    It’s not about how to structure the data, as it’s about limiting the number of documents a query returns, by calling limit(x).

    For example, if you search for "McDonald’s" using the Google Maps app, it will show nearby McDonald’s instead of showing you a McDonald’s 1000 km away.

    That’s correct. You can achieve the same thing also with Cloud Firestore. While @Julian answer might work, please note that his solution is no longer relevant because Firebase recently (4 months ago) added the ability to have range conditions on multiple fields in the same Firestore query.

    So to achieve this, I recommend you see:

    Besides that, I also recommend you read an excellent article written by @FrankvanPuffelen which compares the cost of geohashes vs. the newer approach with range conditions on multiple fields in Firestore:

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search