1

I am trying to build a basic Flutter app where people can swap items (kind of like the Olio app) but I am getting stuck with regards to listings where they only show within a certain radius.

User 1 uploads details of the item they wish to swap (this includes the users UK postcode) to a firebase realtime database.

User 2 wishes to see what items are within their selected search criteria (i.e. within 20 miles).

I'm trying to figure out an efficient way of performing this search? At the moment I just return all items from the realtime database, but need it so that the only items that are returned are that of items within the distance range.

Do I need to download all items (this could be a very large list) and then check each item against a google maps api? This seems very inefficient!

I would really appreciate any pointers in the right direction.

teh_raab
  • 384
  • 1
  • 3
  • 21
  • You'll want to have a look at geofire, an add-on library that allows distance based search: https://stackoverflow.com/questions/43357990/query-for-nearby-locations/43358909#43358909 – Frank van Puffelen Feb 15 '21 at 15:54

1 Answers1

0

this is one of those "many to many" relational problems that Firebase Realtime database really isn't good at. Cloud Firestore however allows you to save geopoints and perform queries on them:

https://firebase.google.com/docs/firestore/solutions/geoqueries

edit: both realtime database and cloud firestore support this apparently, which is great!

cas
  • 757
  • 4
  • 19
  • That solution was actually originally made for the Realtime Database, many years before we ported it to Firestore ;-) https://stackoverflow.com/questions/43357990/query-for-nearby-locations/43358909#43358909 – Frank van Puffelen Feb 15 '21 at 15:55
  • that is awesome! and should definitely feature more prominent in the docs. – cas Feb 15 '21 at 17:58