Exemplo n.º 1
0
        void getForcast(string city)
        {
            int day = 5;
            // api url
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt={1}&APPID={2}", city, day, APPID);

            using (WebClient web = new WebClient()) {
                var json   = web.DownloadString(url);
                var Object = JsonConvert.DeserializeObject <weatherForcast>(json);

                weatherForcast forcast = Object;
                // next day
                lbl_day_2.Text  = string.Format("{0}", getDate(forcast.list[1].dt).DayOfWeek);  //returning Day
                lbl_cond_2.Text = string.Format("{0}", forcast.list[1].weather[0].main);        //weather condition
                lbl_des_2.Text  = string.Format("{0}", forcast.list[1].weather[0].description); //weather description
                lbl_temp_2.Text = string.Format("{0} \u00B0" + "C", forcast.list[1].temp.day);  //weather temperature
                lbl_wind_2.Text = string.Format("{0} km/h", forcast.list[1].speed);             //weather temperature
                // day after tomorrow
                lbl_day_3.Text  = string.Format("{0}", getDate(forcast.list[2].dt).DayOfWeek);  //returning Day
                lbl_cond_3.Text = string.Format("{0}", forcast.list[1].weather[0].main);        //weather condition
                lbl_des_3.Text  = string.Format("{0}", forcast.list[1].weather[0].description); //weather description
                lbl_temp_3.Text = string.Format("{0} \u00B0" + "C", forcast.list[2].temp.day);  //weather temperature
                lbl_wind_3.Text = string.Format("{0} km/h", forcast.list[2].speed);             //weather temperature
                //weather icon
                pic_1.Image = setIcon(forcast.list[1].weather[0].icon);
                pic_2.Image = setIcon(forcast.list[2].weather[0].icon);
            }
        }
Exemplo n.º 2
0
        public async void getForcast(string city)
        {
            int day = 5;
            // api url
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt={1}&APPID={2}", city, day, APPID);

            var http    = new HttpClient();
            var respone = await http.GetAsync(url);

            var data = await respone.Content.ReadAsStringAsync();

            var            result  = JsonConvert.DeserializeObject <weatherForcast>(data);
            weatherForcast forcast = result;

            //// next day
            Condition.Text   = string.Format("{0}: {1}", forcast.list[1].weather[0].main, forcast.list[1].weather[0].description); //weather condition
            Secondday.Text   = string.Format("{0}", getDate(forcast.list[1].dt).DayOfWeek);                                        //returning Day
            TempForcast.Text = string.Format("{0} \u00B0" + "C", forcast.list[1].temp.day);                                        //weather temperature
            string imageurl = string.Format("http://openweathermap.org/img/w/{0}.png", forcast.list[1].weather[0].icon);

            imageForcast.Source   = new BitmapImage(new Uri(imageurl, UriKind.Absolute));
            windSpeedForcast.Text = string.Format("{0} km/h", forcast.list[1].speed); //weather temperature

            //// day after tomorrow
            Condition2.Text   = string.Format("{0}: {1}", forcast.list[2].weather[0].main, forcast.list[2].weather[0].description); //weather condition
            Secondday2.Text   = string.Format("{0}", getDate(forcast.list[2].dt).DayOfWeek);                                        //returning Day
            TempForcast2.Text = string.Format("{0} \u00B0" + "C", forcast.list[2].temp.day);                                        //weather temperature
            string imageurl2 = string.Format("http://openweathermap.org/img/w/{0}.png", forcast.list[2].weather[0].icon);

            imageForcast2.Source   = new BitmapImage(new Uri(imageurl2, UriKind.Absolute));
            windSpeedForcast2.Text = string.Format("{0} km/h", forcast.list[2].speed); //weather temperature
        }
Exemplo n.º 3
0
        void getForcast(string city)
        {
            int    day = 5;
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt={1}&APPID={2}", city, day, APPID);

            using (WebClient web = new WebClient())
            {
                var json   = web.DownloadString(url);
                var Object = JsonConvert.DeserializeObject <weatherForcast>(json);

                weatherForcast forcast = Object;

                // when doing forcast remeber to increase forcast.list by 1 for the corespodning day
                //tomorrow
                lbl_Days.Text        = string.Format("{0}", getDate(forcast.list[1].dt).DayOfWeek);  // returns Day
                lbl_Conditions.Text  = string.Format("{0}", forcast.list[1].weather[0].main);        // weather condition (.text allows label to change)
                lbl_description.Text = string.Format("{0}", forcast.list[1].weather[0].description); // weather description
                lbl_Temp2.Text       = string.Format("{0} \u00B0" + "C", forcast.list[1].temp.day);  // weather temp
                lbl_windspeed.Text   = string.Format("{0} km/h", forcast.list[1].speed);             // weather wind speed

                //day after tomorrow
                lbl_Days2.Text        = string.Format("{0}", getDate(forcast.list[2].dt).DayOfWeek);  // returns Day
                lbl_Conditions2.Text  = string.Format("{0}", forcast.list[2].weather[0].main);        // weather condition (.text allows label to change)
                lbl_description2.Text = string.Format("{0}", forcast.list[2].weather[0].description); // weather description
                lbl_Temp3.Text        = string.Format("{0} \u00B0" + "C", forcast.list[2].temp.day);  // weather temp
                lbl_windspeed2.Text   = string.Format("{0} km/h", forcast.list[2].speed);             // weather wind speed


                //weather icon
                pic_1.Image = setIcon(forcast.list[1].weather[0].icon);
                pic_2.Image = setIcon(forcast.list[2].weather[0].icon);
            }
        }
Exemplo n.º 4
0
        void getForcast(string city)
        {
            int    day = 6;
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt={1}&APPID={2}", city, day, APPID);

            using (WebClient web = new WebClient())
            {
                var json   = web.DownloadString(url);
                var Object = JsonConvert.DeserializeObject <weatherForcast>(json);

                weatherForcast forcast = Object;

                // next day
                label4.Text = string.Format("{0}", getDate(forcast.list[1].dt).DayOfWeek);  //returning Day
                label5.Text = string.Format("{0}", forcast.list[1].weather[0].main);        //weather condition
                label6.Text = string.Format("{0}", forcast.list[1].weather[0].description); //weather description
                label8.Text = string.Format("{0}\u00B0" + "C", forcast.list[1].temp.day);   //weather temp
                label7.Text = string.Format("{0} km/h", forcast.list[1].speed);             //weather wind speed

                //day after tomorrow
                label14.Text = string.Format("{0}", getDate(forcast.list[2].dt).DayOfWeek);  //returning Day
                label13.Text = string.Format("{0}", forcast.list[2].weather[0].main);        //weather condition
                label12.Text = string.Format("{0}", forcast.list[2].weather[0].description); //weather description
                label10.Text = string.Format("{0}\u00B0" + "C", forcast.list[2].temp.day);   //weather temp
                label11.Text = string.Format("{0} km/h", forcast.list[2].speed);             //weather wind speed

                //next other day
                label19.Text = string.Format("{0}", getDate(forcast.list[3].dt).DayOfWeek);  //returning Day
                label18.Text = string.Format("{0}", forcast.list[3].weather[0].main);        //weather condition
                label17.Text = string.Format("{0}", forcast.list[3].weather[0].description); //weather description
                label15.Text = string.Format("{0}\u00B0" + "C", forcast.list[3].temp.day);   //weather temp
                label16.Text = string.Format("{0} km/h", forcast.list[3].speed);             //weather wind speed

                //next next other day
                label25.Text = string.Format("{0}", getDate(forcast.list[4].dt).DayOfWeek);  //returning Day
                label24.Text = string.Format("{0}", forcast.list[4].weather[0].main);        //weather condition
                label23.Text = string.Format("{0}", forcast.list[4].weather[0].description); //weather description
                label21.Text = string.Format("{0}\u00B0" + "C", forcast.list[4].temp.day);   //weather temp
                label22.Text = string.Format("{0} km/h", forcast.list[4].speed);             //weather wind speed

                //next next next other day
                label30.Text = string.Format("{0}", getDate(forcast.list[5].dt).DayOfWeek);  //returning Day
                label29.Text = string.Format("{0}", forcast.list[5].weather[0].main);        //weather condition
                label28.Text = string.Format("{0}", forcast.list[5].weather[0].description); //weather description
                label26.Text = string.Format("{0}\u00B0" + "C", forcast.list[5].temp.day);   //weather temp
                label27.Text = string.Format("{0} km/h", forcast.list[5].speed);             //weather wind speed
            }
        }
Exemplo n.º 5
0
        void getForecast(string city)
        {
            int    day = 5;
            string url = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt={1}&APPID=542ffd081e67f4512b705f89d2a611b2", city, day, APPID);

            using (WebClient web = new WebClient())
            {
                var json   = web.DownloadString(url);
                var Object = JsonConvert.DeserializeObject <weatherForcast>(json);

                weatherForcast forcast = Object;
                //tomorrow
                label4.Text = string.Format("{0}", getDate(forcast.list[1].dt).DayOfWeek);  //returning date
                label5.Text = string.Format("{0}", forcast.list[1].weather[0].main);        //weather condition
                label6.Text = string.Format("{0}", forcast.list[1].weather[0].description); //weather description
                label8.Text = string.Format("{0} \u00B0C", forcast.list[1].temp.day);       //weather temp
                label7.Text = string.Format("{0} km/h", forcast.list[1].speed);             //weather speed


                //aftertomorrow
                label14.Text = string.Format("{0}", getDate(forcast.list[2].dt).DayOfWeek);  //returning date
                label13.Text = string.Format("{0}", forcast.list[2].weather[0].main);        //weather condition
                label12.Text = string.Format("{0}", forcast.list[2].weather[0].description); //weather description
                label10.Text = string.Format("{0} \u00B0C", forcast.list[2].temp.day);       //weather temp
                label11.Text = string.Format("{0} km/h", forcast.list[2].speed);             //weather speed

                //aftertomorrowwww
                label19.Text = string.Format("{0}", getDate(forcast.list[3].dt).DayOfWeek);  //returning date
                label18.Text = string.Format("{0}", forcast.list[3].weather[0].main);        //weather condition
                label17.Text = string.Format("{0}", forcast.list[3].weather[0].description); //weather description
                label15.Text = string.Format("{0} \u00B0C", forcast.list[3].temp.day);       //weather temp
                label16.Text = string.Format("{0} km/h", forcast.list[3].speed);             //weather speed

                //aftertomorrowwww
                label24.Text = string.Format("{0}", getDate(forcast.list[4].dt).DayOfWeek);  //returning date
                label23.Text = string.Format("{0}", forcast.list[4].weather[0].main);        //weather condition
                label22.Text = string.Format("{0}", forcast.list[4].weather[0].description); //weather description
                label20.Text = string.Format("{0} \u00B0C", forcast.list[4].temp.day);       //weather temp
                label21.Text = string.Format("{0} km/h", forcast.list[4].speed);             //weather speed


                //weather Icon Forecast
                pic_1.Image = setIcon(forcast.list[1].weather[0].icon);
                pic_2.Image = setIcon(forcast.list[2].weather[0].icon);
                pic_3.Image = setIcon(forcast.list[3].weather[0].icon);
                pic_4.Image = setIcon(forcast.list[4].weather[0].icon);
            }
        }