public async Task<bool> GravaGeolocalizacao(Geolocalizacao geo) { using (var client = CallAPI.RetornaClientHttp()) { var geoJSON = JsonConvert.SerializeObject(geo); response = await client.PostAsJsonAsync(Constants.uriGravaGeolocalizacao, geoJSON); if (response.IsSuccessStatusCode) return await Task.FromResult(true); } return await Task.FromResult(false); }
public async Task GravaGeolocalizacao(Geolocalizacao geo) { await this.service.GravaGeolocalizacao(geo); }
protected override void OnStart() { try { Action<Task> capturaPosicaoPeriodica = null; capturaPosicaoPeriodica = _task => { var locator = CrossGeolocator.Current; var dbUsuario = new Repositorio<Usuario>(); var usuarioLogado = (dbUsuario.RetornarTodos()).Result.FirstOrDefault(); if (usuarioLogado != null) { if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { locator.DesiredAccuracy = 50; var pos = locator.GetPositionAsync(10000); pos.Wait(); var geo = new Geolocalizacao { Latitude = pos.Result.Latitude, Longitude = pos.Result.Longitude, UsuarioId = usuarioLogado.Id, }; var service = App.Container.Resolve<GeolocalizacaoViewModel>(); service.GravaGeolocalizacao(geo).Wait(); Task.Delay(10000, CancellationToken.None).ContinueWith(capturaPosicaoPeriodica, CancellationToken.None); Debug.WriteLine(String.Format("Posição é: LAT: {0} e LONG {1} - Data: {2}", geo.Latitude, geo.Longitude, DateTime.Now.ToString())); } } }; Task.Delay(10000, CancellationToken.None).ContinueWith(capturaPosicaoPeriodica, CancellationToken.None); } catch (Exception ex) { Insights.Report(ex); } }