public void actualizarMetodo(object sender, EventArgs e) { string baseurl = "http://scmrocket.azurewebsites.net/api/pedidos/" + id.ToString(); var Client = new HttpClient(); Client.MaxResponseContentBufferSize = 256000; var uril = new Uri(baseurl); var response = Client.GetAsync(uril).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var items = JsonConvert.DeserializeObject <PedidoModel>(content); if (items.estado != "Finalizado") { estadoPedido.Text = items.estado; Android.Locations.Location puntoa = new Android.Locations.Location("punto A"); Android.Locations.Location puntob = new Android.Locations.Location("punto B"); puntoa.Latitude = items.latitud; puntoa.Longitude = items.longitud; puntob.Latitude = items.latitudRep; puntob.Longitude = items.longitudRep; distancia.Text = puntoa.DistanceTo(puntob).ToString(); estadoPedido.Text = items.estado; } else if (items.estado == "Finalizado") { Toast.MakeText(ApplicationContext, "El repartidor ha finalizado", ToastLength.Long).Show(); Intent intento = new Intent(this, typeof(MainActivity)); StartActivity(intento); } } }
private void MudancaLocalizacao() { if (ControleMapa.LocalizacaoAtual != null) { if (marcadorPosicao != null) { marcadorPosicao.Remove(); } MarkerOptions options = new MarkerOptions().SetPosition(GMap.CameraPosition.Target).SetTitle("").SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.dot)).Visible(false); marcadorPosicao = GMap.AddMarker(options); marcadorPosicao.Position = new LatLng(ControleMapa.LocalizacaoAtual.Latitude, ControleMapa.LocalizacaoAtual.Longitude); marcadorPosicao.Visible = true; if (ultimaLocalizacao != null) { var distancia = ultimaLocalizacao.DistanceTo(ControleMapa.LocalizacaoAtual); if (distancia > 2) { Bearing = ultimaLocalizacao.BearingTo(ControleMapa.LocalizacaoAtual); txtAngle.Text = Bearing.ToString() + "ยบ"; if (modoDirecao) { Orientacao(); } } } ultimaLocalizacao = ControleMapa.LocalizacaoAtual; } }
public async void actualzarRepartidorMetodo(object sender, EventArgs e) { string baseurl = "http://scmrocket.azurewebsites.net/api/pedidos/" + id.ToString(); var Client = new HttpClient(); Client.MaxResponseContentBufferSize = 256000; var uril = new Uri(baseurl); var response = Client.GetAsync(uril).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var items = JsonConvert.DeserializeObject <PedidoModel>(content); Android.Locations.Location puntoa = new Android.Locations.Location("punto A"); Android.Locations.Location puntob = new Android.Locations.Location("punto B"); puntoa.Latitude = items.latitud; puntoa.Longitude = items.longitud; puntob.Latitude = await latitude(); puntob.Longitude = await longitud(); items.latitudRep = puntob.Latitude; items.longitudRep = puntob.Longitude; distanciaRepartidor.Text = puntoa.DistanceTo(puntob).ToString(); if (Postear(items)) { Toast.MakeText(ApplicationContext, "Actualizado", ToastLength.Long).Show(); } else { Toast.MakeText(ApplicationContext, "Error al actualizar", ToastLength.Long).Show(); } } }
public static DistanceToObject GetDistanceTo(this Android.Locations.Location source, IEnumerable <GeoNode> targets) { var distances = new List <float>(); foreach (var geoNode in targets) { var androidLocation = new Android.Locations.Location(nameof(LocationExtensions)) { Latitude = geoNode.Latitude, Longitude = geoNode.Longitude }; var distance = source.DistanceTo(androidLocation); distances.Add(distance); } return(new DistanceToObject(distances)); }
public void actualizarMetodo() { string baseurl = "http://scmrocket.azurewebsites.net/api/pedidos/" + id.ToString(); var Client = new HttpClient(); Client.MaxResponseContentBufferSize = 256000; var uril = new Uri(baseurl); var response = Client.GetAsync(uril).Result; if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsStringAsync().Result; var items = JsonConvert.DeserializeObject <PedidoModel>(content); estadoPedido.Text = items.estado; Android.Locations.Location puntoa = new Android.Locations.Location("punto A"); Android.Locations.Location puntob = new Android.Locations.Location("punto B"); puntoa.Latitude = items.latitud; puntoa.Longitude = items.longitud; puntob.Latitude = items.latitudRep; puntob.Longitude = items.longitudRep; distancia.Text = puntoa.DistanceTo(puntob).ToString(); estadoPedido.Text = items.estado; } }
void CheckIn(CardMenuPDVsModel item) { try { var isToOpenTarefas = false; CheckApp(); var batery = GetBatteryLevel(); var gpsLocation = GPS.lastLocation; var cordenadaEsperada = controller.GetCoordinates(item.listTypePdv); var gpsEsperado = new Android.Locations.Location("GpsEsperado") { Latitude = cordenadaEsperada[0], Longitude = cordenadaEsperada[1] }; if (gpsEsperado == null) { isToOpenTarefas = true; controller.CheckIn(item.listTypePdv, 0, 0, batery); } else { var distance = gpsEsperado.DistanceTo(gpsLocation); if (distance > 500 && (int)cordenadaEsperada[0] > 0 && (int)cordenadaEsperada[1] > 0) { AlertDialog.Builder dialogBuilder; dialogBuilder = new AlertDialog.Builder(this, Resource.Style.DialogTheme); dialogBuilder.SetTitle(Resources.GetString(Resource.String.PDV_Distante)); dialogBuilder.SetMessage(Resources.GetString(Resource.String.PDV_Distante_descricao)); dialogBuilder.SetPositiveButton(Resources.GetString(Resource.String.sim), delegate { try { controller.CheckIn(item.listTypePdv, gpsLocation.Latitude, gpsLocation.Longitude, batery); controller.RegistroDePontoEletronico(); MetricsManager.TrackEvent("CheckInLoja"); isToRunning = false; var i = new Intent(this, typeof(MenuTarefas)); i.PutExtra("lojaSelecionada", item.name); i.PutStringArrayListExtra("idUser", controller.PrepareIdsUserToIntent()); i.PutExtra("visitas", new ListTypePDV().ToIntentVar(item.listTypePdv)); var options = ActivityOptions.MakeSceneTransitionAnimation(this, Pair.Create(FindViewById(Resource.Id.profile_image_pdv), "profileImage"), Pair.Create(FindViewById(Resource.Id.profileBarLayout), "profileBar"), Pair.Create(FindViewById(Resource.Id.toolbar), "toolbar")); StartActivity(i, options.ToBundle()); } catch (NullReferenceException) { Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } catch (Java.Lang.NullPointerException) { Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } }); dialogBuilder.SetNegativeButton(Resources.GetString(Resource.String.nao), delegate { MetricsManager.TrackEvent("CancelCheckIn"); }); model.modelGeneric.dialog = dialogBuilder.Create(); RunOnUiThread(() => model.modelGeneric.dialog.Show()); } else { try { isToOpenTarefas = true; controller.CheckIn(item.listTypePdv, gpsLocation.Latitude, gpsLocation.Longitude, batery); } catch (NullReferenceException ex) { MetricsManager.TrackEvent("CheckInFail"); MetricsManager.TrackEvent(ex.Message); Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } catch (Java.Lang.NullPointerException exPointer) { MetricsManager.TrackEvent("CheckInFail"); MetricsManager.TrackEvent(exPointer.Message); Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } } } if (isToOpenTarefas) { controller.RegistroDePontoEletronico(); MetricsManager.TrackEvent("CheckInLoja"); var i = new Intent(this, typeof(MenuTarefas)); i.PutExtra("lojaSelecionada", item.name); i.PutStringArrayListExtra("idUser", controller.PrepareIdsUserToIntent()); i.PutExtra("visitas", new ListTypePDV().ToIntentVar(item.listTypePdv)); var options = ActivityOptions.MakeSceneTransitionAnimation(this, Pair.Create(FindViewById(Resource.Id.profile_image_pdv), "profileImage"), Pair.Create(FindViewById(Resource.Id.profileBarLayout), "profileBar"), Pair.Create(FindViewById(Resource.Id.toolbar), "toolbar")); StartActivity(i, options.ToBundle()); } } catch (NullReferenceException) { Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } catch (Java.Lang.NullPointerException) { Toast.MakeText(this, Resources.GetString(Resource.String.erro_checkin), ToastLength.Long).Show(); } }