//Initiate Search private void mainWindow_button_SearchButton_Click(object sender, RoutedEventArgs e) { string MySearch = mainWindow_textBox_search.Text; //Call Weather Channel Service Method, and save the result in a Weather Result Object WeatherResult result = WeatherChannelService.GetWeatherFor(MySearch); //Clear Labels ClearLabels(); //Wire it up mainWindow_label_cityState.Content = result.CityState; mainWindow_label_Latlong.Content = result.Longitude; mainWindow_label_Latlong_Copy.Content = result.Latitude; mainWindow_label_CurrentWeather.Content = result.CurrentWeather; mainWindow_label_Temperature_Data.Content = result.Temperature; mainWindow_label_FeelsLike_Data.Content = result.FeelsLike; mainWindow_label_Wind_Data.Content = result.Wind; mainWindow_label_WindSpeed_Data.Content = result.WindSpeed; mainWindow_label_WindDirection_Data.Content = result.WindDirection; mainWindow_label_Elevation_Data.Content = result.Elevation; mainWindow_label_LastUpdated_Data.Content = result.LastUpdated; mainWindow_label_Humidity_Data.Content = result.Humidity; mainWindow_label_Visibility_Data.Content = result.Visibility; mainWindow_label_UV_Data.Content = result.UV; mainWindow_label_Percipitation_Data.Content = result.Precipitation; //Set image setImage(result); }
public void setImage(WeatherResult result) { //Download the image from the url given to us by the API using (var webClient = new WebClient()) { string imageFilePath = System.IO.Path.Combine(Environment.CurrentDirectory, result.Icon + ".gif"); if (File.Exists(result.Icon + ".gif") == false) { webClient.DownloadFile(result.WeatherIconURL, imageFilePath); } //Change the source of the image in XAML to be the image we just downloaded var uri = new Uri(imageFilePath); mainWindow_Image.Source = new BitmapImage(uri); } }
public void setImage(WeatherResult result) { //Download the image from the url given to us by the API using (var webClient = new WebClient()) { string imageFilePath = System.IO.Path.Combine(Environment.CurrentDirectory, result.Icon + ".gif"); if (File.Exists(result.Icon + ".gif") == false) { webClient.DownloadFile(result.WeatherIconURL, imageFilePath); } //Change the source of the image in XAML to be the image we just downloaded var uri = new Uri(imageFilePath); mainWindow_Image.Source = new BitmapImage(uri); } }
public static WeatherResult GetWeatherFor(string SearchZip) { using (WebClient webClient = new WebClient()) { //Grab userInformation file from Github string json = webClient.DownloadString("https://api.wunderground.com/api/21e1dadd00a6746a/conditions/q/" + SearchZip + ".json"); //Instatize UserInforamtion WeatherResult myWeather = new WeatherResult(); //Convert JSON to user-able variables JObject o = JObject.Parse(json); myWeather.CityState = o["current_observation"]["display_location"]["full"].ToString(); myWeather.Latitude = o["current_observation"]["display_location"]["latitude"].ToString(); myWeather.Longitude = o["current_observation"]["display_location"]["longitude"].ToString(); myWeather.CurrentWeather = o["current_observation"]["weather"].ToString(); myWeather.Elevation = o["current_observation"]["display_location"]["elevation"].ToString(); myWeather.LastUpdated = o["current_observation"]["observation_time"].ToString(); myWeather.Temperature = o["current_observation"]["temperature_string"].ToString(); myWeather.FeelsLike = o["current_observation"]["feelslike_string"].ToString(); myWeather.Wind = o["current_observation"]["wind_string"].ToString(); myWeather.WindDirection = o["current_observation"]["wind_dir"].ToString(); myWeather.WindSpeed = o["current_observation"]["wind_mph"].ToString(); myWeather.Humidity = o["current_observation"]["relative_humidity"].ToString(); myWeather.Visibility = o["current_observation"]["visibility_mi"].ToString(); myWeather.UV = o["current_observation"]["UV"].ToString(); myWeather.Precipitation = o["current_observation"]["precip_today_string"].ToString(); myWeather.WeatherIconURL = o["current_observation"]["icon_url"].ToString(); myWeather.Icon = o["current_observation"]["icon"].ToString(); // return myWeather; } }
public static WeatherResult GetWeatherFor(string SearchZip) { using (WebClient webClient = new WebClient()) { //Grab userInformation file from Github string json = webClient.DownloadString("https://api.wunderground.com/api/21e1dadd00a6746a/conditions/q/" + SearchZip + ".json"); //Instatize UserInforamtion WeatherResult myWeather = new WeatherResult(); //Convert JSON to user-able variables JObject o = JObject.Parse(json); myWeather.CityState = o["current_observation"]["display_location"]["full"].ToString(); myWeather.Latitude = o["current_observation"]["display_location"]["latitude"].ToString(); myWeather.Longitude = o["current_observation"]["display_location"]["longitude"].ToString(); myWeather.CurrentWeather = o["current_observation"]["weather"].ToString(); myWeather.Elevation = o["current_observation"]["display_location"]["elevation"].ToString(); myWeather.LastUpdated = o["current_observation"]["observation_time"].ToString(); myWeather.Temperature = o["current_observation"]["temperature_string"].ToString(); myWeather.FeelsLike = o["current_observation"]["feelslike_string"].ToString(); myWeather.Wind = o["current_observation"]["wind_string"].ToString(); myWeather.WindDirection = o["current_observation"]["wind_dir"].ToString(); myWeather.WindSpeed = o["current_observation"]["wind_mph"].ToString(); myWeather.Humidity = o["current_observation"]["relative_humidity"].ToString(); myWeather.Visibility = o["current_observation"]["visibility_mi"].ToString(); myWeather.UV = o["current_observation"]["UV"].ToString(); myWeather.Precipitation = o["current_observation"]["precip_today_string"].ToString(); myWeather.WeatherIconURL = o["current_observation"]["icon_url"].ToString(); myWeather.Icon = o["current_observation"]["icon"].ToString(); // return(myWeather); } }