Ejemplo n.º 1
0
        public async Task <RutasMS> ObtenerRuta(RutasME mensajeEntrada)
        {
            RutasMS response2 = new RutasMS();

            try
            {
                HttpClient client = new HttpClient();
                client.DefaultRequestHeaders.Add("User-Agent", "App Movil");

                var json    = JsonConvert.SerializeObject(mensajeEntrada);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                string uri = ApiUrl + "?mode=driving&transit_routing_preference=less_driving&origin=" + mensajeEntrada.RutaInicial.Latitud + "," + mensajeEntrada.RutaInicial.Longitud
                             + "&destination=" + mensajeEntrada.RutaFinal.Latitud + "," + mensajeEntrada.RutaFinal.Longitud
                             + "&key=YourApiKeyHere";

                HttpResponseMessage response = await client.GetAsync(uri);

                var responseString = await response.Content.ReadAsStringAsync();

                response2 = JsonConvert.DeserializeObject <RutasMS>(responseString);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(response2);
        }
Ejemplo n.º 2
0
        public async void ObtenerDatos()
        {
            try
            {
                string tempLatitud, tempLongitud;
                var    position = await ProcesaTareaObtenerPosicion(TimeSpan.FromSeconds(10000));

                tempLatitud  = position.Latitude.ToString();
                tempLongitud = position.Longitude.ToString();
                Rutas.Clear();
                Pines.Clear();
                Pines.Add(new Pin()
                {
                    Position = new Position(Convert.ToDouble(tempLatitud), Convert.ToDouble(tempLongitud)), Type = PinType.Generic, Label = "Yo"
                });

                foreach (var rutas in RutaVisitadas)
                {
                    RutasME ruta = new RutasME()
                    {
                        RutaInicial = new UbicacionMS()
                        {
                            Latitud = tempLatitud, Longitud = tempLongitud
                        }, RutaFinal = new UbicacionMS()
                        {
                            Latitud = rutas.Latitud, Longitud = rutas.Longitud
                        }
                    };

                    _ruta = await _servicioGoogle.ObtenerRuta(ruta);

                    Rutas.Add(new Position(Convert.ToDouble(tempLatitud), Convert.ToDouble(tempLongitud)));

                    foreach (var item in _ruta.routes)
                    {
                        foreach (var item2 in item.legs)
                        {
                            foreach (var item3 in item2.steps)
                            {
                                Rutas.Add(new Position(Convert.ToDouble(item3.start_location.lat), Convert.ToDouble(item3.start_location.lng)));
                                List <Position> decodificacion = DecodePolyline(item3.polyline.points);
                                foreach (var item4 in decodificacion)
                                {
                                    Rutas.Add(new Position(Convert.ToDouble(item4.Latitude), Convert.ToDouble(item4.Longitude)));
                                }
                                Rutas.Add(new Position(Convert.ToDouble(item3.end_location.lat), Convert.ToDouble(item3.end_location.lng)));
                            }
                        }
                    }
                    Rutas.Add(new Position(Convert.ToDouble(ruta.RutaFinal.Latitud), Convert.ToDouble(ruta.RutaFinal.Longitud)));
                    tempLatitud  = rutas.Latitud;
                    tempLongitud = rutas.Longitud;
                    Pines.Add(new Pin()
                    {
                        Position = new Position(Convert.ToDouble(tempLatitud), Convert.ToDouble(tempLongitud)), Type = PinType.Generic, Label = "lugar"
                    });
                }
            }
            catch (Exception ex)
            {
                _userDialogs.Toast(ex.Message);
            }
        }