private static List <WeatherDetail> GetWeatherInfo(OpenWeatherMap.RootObject root) { var weatherDetails = new List <WeatherDetail>(); foreach (var list in root.list) { var weatherDetail = new WeatherDetail(); var dateTime = DateTimeOffset.FromUnixTimeSeconds(list.dt); weatherDetail.date = dateTime.Date.ToString("dd MMM, yyyy"); weatherDetail.dayOfWeek = dateTime.DayOfWeek.ToString(); weatherDetail.humidity = $"{list.humidity} %"; weatherDetail.windSpeed = $"{list.speed} mps"; if (list.weather != null) { weatherDetail.icon = $"http://openweathermap.org/img/w/{list.weather[0].icon}.png"; weatherDetail.weather = list.weather[0].main; weatherDetail.description = list.weather[0].description; } if (list.temp != null) { weatherDetail.maxTemp = $"{list.temp.max.Floor()} °C"; weatherDetail.minTemp = $"{list.temp.min.Floor()} °C"; weatherDetail.temp = $"{list.temp.day.Floor()} °C"; } weatherDetails.Add(weatherDetail); } return(weatherDetails); }
public String[] CurrentWeather(String place) { using (WebClient wcumum = new WebClient()) { string request = string.Format("http://api.openweathermap.org/data/2.5/weather?q={0}&appid={1}&units=metric&lang=nl", place, Apikey); var jsonres = wcumum.DownloadString(request); var objectres = JsonConvert.DeserializeObject <OpenWeatherMap.RootObject>(jsonres); OpenWeatherMap.RootObject resultobj = objectres; var arr1 = new string[] { resultobj.Name, resultobj.Weather[0].Description, resultobj.Main.Temp.ToString(), resultobj.Main.Humidity.ToString(), resultobj.Wind.Speed.ToString(), "http://openweathermap.org/img/w/" + resultobj.Weather[0].Icon + ".png" }; return(arr1); } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { if (NetworkInterface.GetIsNetworkAvailable()) { var postion = await ApiHandle.GetPosition(); #pragma warning disable CS0618 // Type or member is obsolete var lat = postion.Coordinate.Latitude; #pragma warning restore CS0618 // Type or member is obsolete #pragma warning disable CS0618 // Type or member is obsolete var lon = postion.Coordinate.Longitude; #pragma warning restore CS0618 // Type or member is obsolete OpenWeatherMap.RootObject forecast = await ApiHandle.GetWeather(lat, lon); CityTextBlock.Text = forecast.city.name; for (int i = 0; i < forecast.list.Count; i++) { //collection.Add(forecast.list[i]); for (int j = 0; j < forecast.list[i].weather.Count; j++) { string icon = string.Format("ms-appx:///Assets/Weather/{0}.png", forecast.list[i].weather[j].icon); var listReplace = forecast.list[i].weather[j]; listReplace.icon = icon; } collection.Add(forecast.list[i]); } ForeCastGridView.ItemsSource = collection; } } catch (Exception exception) { Debug.WriteLine(exception); } }