private async void BtnConsulta_Clicked(object sender, EventArgs e) { using (var cliente = new HttpClient()) { // string apikey = "b73171bf7ac8904c46d9067bc99880f9"; string url = "http://api.openweathermap.org/data/2.5/weather?q=" + Ciudad.Text + "&appid=b73171bf7ac8904c46d9067bc99880f9&units=metric&lang=es"; Task <string> taskjsontxt = cliente.GetStringAsync(url); lblResultado.Text = "Consultando..."; var jsontxt = await taskjsontxt; var data = OpenWheatherClass.FromJson(jsontxt); lblResultado.Text = "Nombre estacion: " + data.Name + "\nCiudad: " + Ciudad.Text + "\nPais: " + data.Sys.Country + "\nTemperatura: " + data.Main.Temp + "ºC\nHumedad: " + data.Main.Humidity + "%\nDescripción: " + data.Weather[0].Description; lbltemperatura.Text = data.Main.Temp + "Grados "; //string iconourl = "http://openweathermap.org/img/w/" + data.Weather[0].Icon + ".png"; //UriImageSource img = new UriImageSource(); //img.Uri = new Uri(iconourl); //Icono.Source = img; Icono.Source = ImageSource.FromResource("ET_6_2OpenWheater.Images.Weather." + data.Weather[0].Icon + ".png"); BtnHablame_Clicked(sender, e); } }
public static string ToJson(this OpenWheatherClass self) => JsonConvert.SerializeObject(self, ET_6_2OpenWheater.Converter.Settings);