public async Task <WeatherInfo.RootObject> GetWeather(string cityName) { WeatherInfo.RootObject result = null; try { var url = BaseUrl + cityName + UrlQueryString; var json = await httpClient.GetAsync(url); if (json.IsSuccessStatusCode) { var jsonContent = await json.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <WeatherInfo.RootObject>(jsonContent); } } catch (System.Exception) { Toast.MakeText(Application.Context, "Cannot load data", ToastLength.Short).Show(); } return(result); }
public void GetWeather(string city) { try { WebClient client = new WebClient(); string url = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&APPID=42c1d2a0b9b958f4fbb51e0edc9896a0", city); //json format (weather info api) var json = client.DownloadString(url); var results = JsonConvert.DeserializeObject <WeatherInfo.RootObject>(json); WeatherInfo.RootObject Output = results; //wyswietlanie informacji lActualTemp.Content = string.Format("{0:N1} \u00B0" + "C", Output.main.temp - 273.15); //przeliczenie temp lLocation.Content = city.ToUpper(); image1.Source = SetIcon(Output.weather[0].icon); lActualPressure.Content = string.Format("{0} hPa", Output.main.pressure); lActualHumidity.Content = string.Format("{0} %", Output.main.humidity); lActualWind.Content = string.Format("{0} m/s", Output.wind.speed); } catch (Exception) { MessageBox.Show("Błędna nazwa miejscowości"); } }