Search code examples
firebasegeolocationfirebase-realtime-databasegeofire

Firebase/GeoFire - Most popular item at location


I am currently in the evaluation process for a database that should serve as a backend for a mobile application.


Right now I am looking at Firebase, and for now I like it really much.


It is a requirement to have the possibility to fetch the

  1. most popular items
  2. at a certain location
  3. (possibly in the future: additionally for a certain time range that would be an attribute of the item)

from the database.


So naturally I stumbled upon GeoFire that provides location based query possibilities for Firebase.

Unfortunately - at least as far as I understood - there is no possibility to order the results by an attribute other than the distance. (correct me if I am wrong).

So what do I do if I am not interested in the distance (I only want to have items in a certain radius, no matter how far from the center) but in the popularity factor (e.g. for the sake of simplicity a simple number that symbolizes popularity)?

IMPORTANT:
Filtering/Sorting on the client-side is not an option (or at least the least preferred one), as the result set could potentially grow to an infinite amount.


First version of the application will be for android, so the Firebase Java Client Library would be used in the first step.


Are there possibilities to solve this or is Firebase out of the race and not the right candidate for the job?


Solution

  • There is no way to add an extra condition to the server-side query of Geofire.

    The query model of the Firebase database allows filtering only on a single property. Geofire already performs a seemingly impossible feat of filtering on both latitude and longitude. It does this through the magic of Geohashes, which combine latitude and longitude into a single string.

    Strictly speaking you could find a way to extend the magic of Geohashes to add a third number into the mix. But while possible, I doubt it's feasible for most of us.