public async void SendLocation(BackgroundLocationModel location) { var locationAsString = JsonConvert.SerializeObject(location); HttpContent content = new StringContent(locationAsString, Encoding.UTF8); content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); ApplicationDataContainer localData = ApplicationData.Current.LocalSettings; var token = localData.Values["accessToken"].ToString(); this.client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", token); var result = await this.client.PostAsync(LOCATIONS_URL, content); }
public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); var locator = new Geolocator(); locator.DesiredAccuracyInMeters = 50; var position = await locator.GetGeopositionAsync(); var lat = position.Coordinate.Point.Position.Latitude; var lon = position.Coordinate.Point.Position.Longitude; var location = new BackgroundLocationModel() { Latitude = lat, Longitude = lon }; var requester = new HttpLocationSender(); requester.SendLocation(location); deferral.Complete(); }