private void mostrarDatos(Gasolinera gasolinera) { txtGasoleo.Content = gasolinera.Precio_x0020_Gasoleo_x0020_A + " €"; txtCP.Content = gasolinera.CP; txtDireccion.Content = gasolinera.Dirección; txtHorario.Content = gasolinera.Horario; }
public info(string id, string idMunicipio) { InitializeComponent(); gasolineras = obtenerGasolineras(idMunicipio); gasolineras = gasolineras.Where(gas => gas.IDEESS.Contains(id)).ToList(); Gasolinera gasolinera = new Gasolinera(); gasolinera = gasolineras[0]; mostrarDatos(gasolinera); }
private void rbCaro_Click(object sender, RoutedEventArgs e) { if (rbCaro.IsChecked == true) { if (cbMunicipio.Items.Count > 0 && muniSelected == true) { miMapa.Children.Clear(); var idMunicipio = ((ComboBoxItem)cbMunicipio.SelectedItem).Tag.ToString(); List <Gasolinera> gasolineras = obtenerGasolineras(idMunicipio); gasolineras = gasolineras.OrderByDescending(gas => gas.Precio_x0020_Gasoleo_x0020_A).ToList(); Gasolinera gasolinera = gasolineras[0]; double lat = Convert.ToDouble(gasolinera.Latitud); double lon = Convert.ToDouble(gasolinera.Longitud_x0020__x0028_WGS84_x0029_); cargarGasolinera(lat, lon, gasolinera.IDEESS); } } }
private List <Gasolinera> obtenerGasolineras(string id) { Gasolinera gasolinera = new Gasolinera(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://sedeaplicaciones.minetur.gob.es/ServiciosRESTCarburantes/PreciosCarburantes/EstacionesTerrestres/FiltroMunicipio/" + id); request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); Console.WriteLine("Content length is {0}", response.ContentLength); Console.WriteLine("Content type is {0}", response.ContentType); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); var salida = readStream.ReadToEnd(); JsonDocument gas = JsonDocument.Parse(salida); JsonElement estaciones = gas.RootElement.GetProperty("ListaEESSPrecio"); var salidaText = estaciones.GetRawText(); var settings = new JsonSerializerSettings(); settings.ContractResolver = new CustomContractResolver(); List <Gasolinera> gasolineras = null; gasolineras = JsonConvert.DeserializeObject <List <Gasolinera> >(salidaText, settings); return(gasolineras); }