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 ! :-)