Posted on

Android Algolia vs Geofire

android algolia

Although Firebase is simple to setup, there’re some things that aren’t as simple. I’m talking about Geofire, especially if you’re building realtime location listener. Let’s see at some other options

At its very core Geofire isn’t simple. You need to setup two listeners: one for keys, another for values. Then you need to wait till all initial values fetched, just to optimize RecyclerView and notify data set change only once. And then handling realtime updates if you want

If that seems too much and you just want to find stuff by location and don’t use realtime updates, then Algolia is a great solution for you


What they offer is a great search service for any platform and they have all the different client api’s. How it works is you store data on their server’s index and make queries to it. For example we have a node of users on Firebase, we use geofire for location. With Algolia you just mirror users to their index and keep _geolocĀ field with lat lng in it so they are searchable by location.

Android Client

Sign up at Algolia, create new project and add users index

add this dependency

now when saving user to Firebase instead of saving him to Geofire add him to Algolia index

Query by Location

Instead of Geofire spaggetti code you have this

jsonObject is a list of all the users in the radius of 50 km to you and they are sorted by distance already, unlike inĀ Geofire. But you can’t listen for updates, it’s just a simple rest api technically, with the simplicity of Firebase and you can use it for cases where you don’t care about real time updates and use Firebase for stuff like messaging.

Plus on Geofire you can’t limit number of returned items. Here you can. Yes, you can wait till you get 20 items in onItemEntered with Geofire and don’t handle items added after those, but those 20 will be sorted by key, not distance. And if distance matters for you and you need to display 20 closest restaurants to you it’s a big problem. If you have 9000 restaurants around you, you’ll have to fetch all their id’s, then sort them by distance on Android and only after that you fetch first 20. This is really slow.

With Algolia it’s just that query which returns 20 items by default max in few millis and you’re sure that those 20 are the closest to you.


And of course search itself is great when you want to find by field values. Once again, you can use both Firebase when you want real time updates and Algolia for simplicity to retrieve data because you store it on both of them.


You can get source code here, algolia branch, master is for Geofire. Don’t forget to subscribe, follow me on Twitter, Facebook, G+ and share with friends if you think they will benefit from it!