3

I am creating an app which display sport activities on a map around the use's current location.
The sports activities are stored in a Firebase database. There is more than 15k activities.

To do that, I use Firebase and Geofire in a Xamarin.Forms project : I use two nuget packages : FirebaseAuthentication.net and FireSharp.

I don't have any problems for Authentication.

But I'm quite limited with FireSharp : it uses the REST API of Firebase, and is not optimized for geo-queries as GeoFire is.

This is GeoFire : https://github.com/firebase/geofire-java

And this is FireSharp : https://github.com/ziyasal/FireSharp

For instance, with GeoFire, querying "all sport activities around a lat/lon" is pretty simple (this is a nativ Android sample) :

// creates a new query around [37.7832, -122.4056] with a radius of 0.6 kilometers
GeoQuery geoQuery = geoFire.queryAtLocation(new GeoLocation(37.7832, -122.4056), 0.6);

And it returns the full corresponding activities, in 300ms, using 1 Http request.

With FireSharp, to do that, I need to :

  • 1 : query GeoFire objects with lat lon and the "Geo Hash" :

    //Build the query
    QueryBuilder query = QueryBuilder.New().OrderBy("g").StartAt(geohash1).EndAt(geohash2);
    
    //Send the Http query with FireSharp
    var response = await Instance.m_firebaseActivitieApp.GetAsync("activites_locations", query);
    
    //Deserialize the response from server and construct the list of GeoFire objects
    var results = JsonConvert.DeserializeObject<IDictionary<string, GeofireObject>>(response.Body);
    foreach (var item in results)
            GeoActivities.Add(new GeoFireActivity() { IdActivity = item.Key, GeoActivity = item.Value });
    
  • 2 : browse the GeoFire objects returned, and make an Http request for each one to retrieve the full corresponding object :

    //Browse every GeoFire objects
    foreach (var GeoAct in GeoActivities)
    {
        //Send a Http request with FireSharp to get the sport activity object
        var response = await Instance.m_firebaseActivitieApp.GetAsync(WebUtility.UrlEncode("activites/" + GeoAct.IdActivity);
    
       //Deserialize the result from the server and construct the sport activity object
       Activite res = JsonConvert.DeserializeObject<Activite>(response.Body);
    

    }

And this is during 200ms for the first query, and 800ms for each activity query, because there is more than 15k activities in the Firebase database. To load 40 activities, I need to wait 35 seconds... This is not acceptable for my app.

I would like to know if there is a way to use GeoFire in my Xamarin.Forms project ? I tried to create a Binding Library, but it didn't worked. The binding library compiled, but I am not able to instantiate any GeoFire object in my Xamarin.Forms application.

GeoFire is available in Java for android, Objective C/Swift for iOS, JavaScript for web... Any chance to get it in C# for Xamarin ? (https://github.com/firebase/geofire)

Please help ! :-)

Maxime Esprit
  • 705
  • 1
  • 8
  • 29
  • 1
    I've used GeoFire in C# as the FirebaseDB was being shared among many clients and I needed to create a C# Admin tool. It is all about how the string hashes that are geo-encoded and thus can be queried and is totally language agnostic. In the Java version of `core` you will find GeoHash and GeoHashQuery, these are easy to convert to C# and from there you can convert the rest and normalize them to C# if desired (I used `System.Reactive`, but Action or EventHandler callbacks from the Firebase queries would also work...) – SushiHangover Jun 28 '18 at 09:25
  • Chears SushiHangover :) How many times you helped me in this kind of situation ^^ I'll take a look and post an answer if I succeed. Thanks – Maxime Esprit Jun 28 '18 at 09:55
  • I finally translated the whole GeoFire library into C#. Now it's working well, but it cost a lot of energy... I've used EventHandlers – Maxime Esprit Jul 04 '18 at 14:49
  • 1
    Glad to hear it ;-) I wish I could have shared mine, but it was a work for hire project and the client "owns" the translation for another 5 months before I can open-source it (maybe you will be allowed to post it to GitHub...) – SushiHangover Jul 04 '18 at 14:57
  • @MaximeEsprit Hi Maxime, any chance to share your GeoFire library ? I'm looking to do the same, but if it is already done it is of course welcome LOL ! It will be good for you too because I can also test, fix bugs and maybe help you to improve it if needed ! Thanks – ClubberLang Aug 24 '18 at 08:43
  • The best advice I could give is : don't use Firebase and Geofire ! Use SQL instead. Even by translating the Geofire nativ library into C#, the app is still really slow because of Firebase and Geofire. Geofire returns a list of IDs, and foreach ID Firebase get the corresponding object : it creates as many HTTP request as IDs in the list. I can show you how to use Geoloc in SQL : it is very easy and you will get the entire list of objects in one HTTP request – Maxime Esprit Aug 25 '18 at 10:48

0 Answers0