This class decribes the weather's parameters that provided by the web service.
예제 #1
0
        public static async Task<Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "YOUR API KEY HERE";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                + zipCode + ",us&appid=" + key + "&units=imperial";

            var results = await DataService.getDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind = (string)results["wind"]["speed"] + " mph";
                weather.Humidity = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset = sunset.ToString() + " UTC";
                return weather;
            }
            else
            {
                return null;
            }
        }
예제 #2
0
		public void UpdateData (Weather weather)
		{
			imgWeather.Image = UIImage.FromBundle(weather.CurrentConditions.ToString() + ".png");

			lblCity.Text = weather.City;
			lblHigh.Text = String.Format ("{0}", weather.High);
			lblLow.Text = String.Format ("{0}", weather.Low);
		}
예제 #3
0
        public static async Task<Weather> GetWeather(string zipCode)
        {
            //Sign up for a free API key at http://openweathermap.org/appid
            string key = "YOUR API KEY HERE";
            string queryString = "http://api.openweathermap.org/data/2.5/weather?zip="
                + zipCode + ",us&appid=" + key + "&units=imperial";

            //Make sure developers running this sample replaced the API key
            if (key == "YOUR API KEY HERE")
            {
                throw new ArgumentException("You must obtain an API key from openweathermap.org/appid and save it in the 'key' variable.");
            }

            var results = await DataService.GetDataFromService(queryString).ConfigureAwait(false);

            if (results["weather"] != null)
            {
                Weather weather = new Weather();
                weather.Title = (string)results["name"];
                weather.Temperature = (string)results["main"]["temp"] + " F";
                weather.Wind = (string)results["wind"]["speed"] + " mph";
                weather.Humidity = (string)results["main"]["humidity"] + " %";
                weather.Visibility = (string)results["weather"][0]["main"];

                DateTime time = new System.DateTime(1970, 1, 1, 0, 0, 0, 0);
                DateTime sunrise = time.AddSeconds((double)results["sys"]["sunrise"]);
                DateTime sunset = time.AddSeconds((double)results["sys"]["sunset"]);
                weather.Sunrise = sunrise.ToString() + " UTC";
                weather.Sunset = sunset.ToString() + " UTC";
                return weather;
            }
            else
            {
                return null;
            }
        }
예제 #4
0
        private void citiesList_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            citiesList.Visibility = Visibility.Collapsed;
                string location = citiesList.SelectedValue.ToString();

                weather = new Weather();

                string city, country;
                int comaIndex = location.IndexOf(',');
                country = location.Substring(comaIndex + 1);
                city = location.Remove(comaIndex);

                City cityFound = CityList.FirstOrDefault<City>(c => c.name == city | c.country == country);

                weather.GetWeatherById(cityFound._id);

                lblLocation.Text = weather.City + ", " + weather.Country;
                lblMinMaxTemp.Content = weather.MinTemperature + "/" + weather.MaxTemperature;
                lblHumidity.Content = weather.Humidity;
                lblDescription.Content = weather.Sky;
                lblPressure.Content = weather.Pressure;
                lblSunsetSunrise.Content = "Рассвет: " + weather.Sunrise + " Закат: " + weather.Sunset;
                lblWind.Content = "Ветер: " + weather.WindSpeed;
                lblCurrentTemp.Content = weather.Temperature;
                btnMap.Visibility = Visibility.Visible;
        }
예제 #5
0
 public async Task UpdateAllWeather()
 {
     CurrentWeather = await Model.GetWeather();
 }
예제 #6
0
        public App()
        {
            InitializeComponent();

            MainPage = new Weather();
        }