public async void DontSendCurrentLocationAnymoreAsync() { GeolocationRequest request; request = new GeolocationRequest(GeolocationAccuracy.Best); Xamarin.Essentials.Location location; try { location = await Geolocation.GetLocationAsync(request); Models.Location customLocation = new Models.Location(location); await customLocation.GetRegion(); PrimitiveLocation primitiveLocation = new PrimitiveLocation(customLocation); var conn = new SQLiteAsyncConnection(App.FilePath); conn.CreateTableAsync <PrimitiveLocation>().Wait(); await conn.InsertAsync(primitiveLocation).ContinueWith((t) => { Debug.WriteLine("New ID from t: {0}", t.Id); Debug.WriteLine("New ID: {0} from customLocation", primitiveLocation.LocationId); }); await conn.CloseAsync(); } catch (Exception e) { //TODO: // retry to get the location } }
/// <summary> /// Sends the user's location to the server if the distance is to the last request is larger than 10m, otherwise an exponential backoff occrus /// Backoff = (previous backoff ^ 2) /// </summary> protected async void Track() { bool success = false; int retry = 0; retry = 0; try { // TODO: // faster they go, the more locations sent and slower they go the less request = new GeolocationRequest(GeolocationAccuracy.Best); Xamarin.Essentials.Location location = null; if (Previous_request != null) { location = await Geolocation.GetLocationAsync(request); Models.Location customLocation = new Models.Location(location); if (!LocationService.LocationSavedToNotSend(customLocation)) { if (location.CalculateDistance(Previous_request, DistanceUnits.Kilometers) >= MetersConsidedUserMoved) { await customLocation.GetRegion(); _Backoff = Initial_Backoff; Track_Retry = 0; SendUserLocation(customLocation); } else { ExtendBackoff(); SendUserLocation(customLocation); } } else { ExtendBackoff(); } } else { location = await Geolocation.GetLocationAsync(request); Models.Location customLocation = new Models.Location(location); if ((!LocationService.LocationSavedToNotSend(customLocation))) { await customLocation.GetRegion(); SendUserLocation(customLocation); } } Previous_request = location; success = true; } catch (Exception e) { Debug.WriteLine(e.StackTrace); //retry for getting the geolocation retry++; } }