private async void Button_Click(object sender, RoutedEventArgs e) { try { var position = await LocationManager.GetPosition(); var lat = position.Coordinate.Point.Position.Latitude; var lon = position.Coordinate.Point.Position.Longitude; RootObject myWeather = await OpenWeatherMapProxy.GetWeather(lat, lon);//exei 8ema var uri = String.Format("http://myweatherservice1.azurewebsites.net/?lat={0}&lon={1}", lat, lon); var tileContent = new Uri(uri); var requestedInterval = PeriodicUpdateRecurrence.HalfHour; var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.StartPeriodicUpdate(tileContent, requestedInterval); string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); TempTextBlock.Text = ((int)myWeather.main.temp).ToString(); DescriptionTextBlock.Text = myWeather.weather[0].description; LocationTextBlock.Text = myWeather.name; //RootObject1 FutureWeather = await GetFutureWeather(lat, lon); //FutureWeather. } catch { LocationTextBlock.Text = "Check your Internet connection or open your location"; } }
private async void Button_click(object sender, RoutedEventArgs e) { RootObject myWeather = await OpenWeatherMapProxy.GetWeather(lat, lon); string tmp = DateTime.Now.ToString("HH"); int cmp = 99; string precipitation = ""; string sky = ""; string cur_temp = ""; foreach (Item it in myWeather.response.body.items.item) { if (it.category == "TMN") { Min_temp.Text = "최저기온 : " + it.fcstValue + "℃"; } else if (it.category == "TMX") { Max_temp.Text = "최고기온 : " + it.fcstValue + "℃"; } int t = Math.Abs(Int32.Parse(tmp) - Int32.Parse(it.fcstTime)); if (t <= cmp) { cmp = t; if (it.category == "POP") { precipitation = it.fcstValue; } else if (it.category == "SKY") { sky = it.fcstValue; } else if (it.category == "T3H") { cur_temp = it.fcstValue; } } } if (sky == "1") { Sky.Text = "맑음"; img.Source = new BitmapImage(new Uri("ms-appx:///Assets/sunny.png")); } else if (sky == "3" || sky == "4") { if (Int32.Parse(precipitation) < 80) { Sky.Text = "구름"; img.Source = new BitmapImage(new Uri("ms-appx:///Assets/clouds.png")); } else { Sky.Text = "구름"; img.Source = new BitmapImage(new Uri("ms-appx:///Assets/rain.png")); } } Precipitation.Text = "강수확률 : " + precipitation + "%"; Cur_temp.Text = cur_temp + "℃"; }
private async void Button_Click(object sender, RoutedEventArgs e) { RootObject myWeather = await OpenWeatherMapProxy.GetWeather(20.0, 30.0); ResultTextBlock.Text = "Vaša pozicija: " + myWeather.name + "\nTemperatura: " + myWeather.main.temp + "\nOpis: " + myWeather.weather[0].description; string icon = String.Format("http://openweathermap.org/img/w/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); }
private async void GetWeather_OnClick(object sender, RoutedEventArgs e) { RootObject myWeather = await OpenWeatherMapProxy.GetWeather(20.0, 30.0, "98bb0e6881d8f402f21bf1a3eeb97a17"); string icon = String.Format("http://openweathermap.org/img/w/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); ResultTextBlock.Text = myWeather.name + " - " + myWeather.main.temp + " - " + myWeather.weather[0].description; }
private async void Button_Click(object sender, RoutedEventArgs e) { var position = await LocationManager.GetPosition(); RootObject myWeather = await OpenWeatherMapProxy.GetWeather(21.028511, 105.804817); string icon = String.Format("http://openweathermap.org/img/w/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); ResultTextBlock.Text = myWeather.name + " - " + ((int)myWeather.main.temp).ToString() + " - " + myWeather.weather[0].description; }
public async void getWeather(String plaats, Model.Weather weather) { RootObject myWeather = await OpenWeatherMapProxy.GetWeather(plaats); string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon); weather.Naam = plaats; weather.Temperatuur = ((int)myWeather.main.temp).ToString() + "°"; weather.Description = myWeather.weather[0].description; weather.Icon = new BitmapImage(new Uri(icon, UriKind.Absolute)); }
// GET: Home public async Task <ActionResult> Index(string lat, string lon) { double latitude = double.Parse(lat, CultureInfo.InvariantCulture); double longitude = double.Parse(lon, CultureInfo.InvariantCulture); var weather = await OpenWeatherMapProxy.GetWeather(latitude, longitude); ViewBag.Temp = weather.main.temp.ToString(); ViewBag.Description = weather.weather[0].description; ViewBag.Name = weather.name; return(View()); }
private async void Button_Click(object sender, RoutedEventArgs e) { try { var position = await LocationManager.GetPosition(); RootObject myWeather = await OpenWeatherMapProxy.GetWeather( position.Coordinate.Latitude, position.Coordinate.Longitude); string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); TempTextBlock.Text = ((int)myWeather.main.temp).ToString() + "°C"; LocationTextBlock.Text = myWeather.name; DescriptionTextBlock.Text = myWeather.weather[0].description; } catch { LocationTextBlock.Text = "Unable to get weather at this time."; } }
/// <summary> /// get weather from api /// </summary> /// <param name="item"></param> /// <param name="units"></param> /// <returns >RootObject</returns> public async Task <RootObject> requestWeather(WeatherData_ListVM item, bool units) { item.ReqWeather = await OpenWeatherMapProxy.GetWeather(item.Reqlocation, units); return(item.ReqWeather); }
/// <summary> /// get weather from api /// </summary> /// <param name="item"></param> /// <param name="units"></param> /// <returns></returns> public async Task requestWeather_item(WeatherData_ListVM item, bool units) { item.ReqWeather = await OpenWeatherMapProxy.GetWeather(item.Reqlocation, units); }
private async void Florida_Loaded(object sender, RoutedEventArgs e) { int zipcode = 33709; RootObject myWeather = await OpenWeatherMapProxy.GetWeatherAsync(zipcode); //make the background flBackgroundIcon = myWeather.weather[0].icon; string flWeatherIcon = String.Format("ms-appx:///Assets/Florida/{0}.png", flBackgroundIcon); ImageBrush ib = new ImageBrush(); ib.ImageSource = new BitmapImage(new Uri(flWeatherIcon, UriKind.Absolute)); ib.Stretch = Stretch.UniformToFill; Florida.Background = ib; //weather info flName.Text = myWeather.name; flTemp.Text = "Temp: " + ((int)myWeather.main.temp).ToString() + " F"; flCondition.Text = myWeather.weather[0].description; //sunrise and sunset var sunrise = DateTimeOffset.FromUnixTimeSeconds(myWeather.sys.sunrise); sunrise += TimeSpan.FromHours(-5); var sunset = DateTimeOffset.FromUnixTimeSeconds(myWeather.sys.sunset); sunset += TimeSpan.FromHours(-5); flSunrise.Text = "sunrise: " + sunrise.ToString("hh':'mm") + " AM"; flSunset.Text = "sunset: " + sunset.ToString("hh':'mm") + " PM"; //toggle light if (isPiConnected) { int _flCurrentTemp = (int)myWeather.main.temp; ToggleLight.checkTemp(_flCurrentTemp, zipcode, isSourKrautAwake, ref isFloridaFreezing, ref isColoradoFreezing, ref pinValue, pin); } //Florida Timer TimeSpan period = TimeSpan.FromMinutes(10); ThreadPoolTimer PerodicTimer = ThreadPoolTimer.CreatePeriodicTimer(async(Florida_Loaded) => { myWeather = await OpenWeatherMapProxy.GetWeatherAsync(zipcode); string newflBackgroundIcon = myWeather.weather[0].icon; var moment = DateTime.Now; if (moment.Hour > 22 || moment.Hour < 5) { isSourKrautAwake = true; } else { isSourKrautAwake = false; } if (isPiConnected) { int _flCurrentTemp = (int)myWeather.main.temp; ToggleLight.checkTemp(_flCurrentTemp, zipcode, isSourKrautAwake, ref isFloridaFreezing, ref isColoradoFreezing, ref pinValue, pin); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { //remake the background if it changes if (newflBackgroundIcon != flBackgroundIcon) { flBackgroundIcon = newflBackgroundIcon; flWeatherIcon = String.Format("ms-appx:///Assets/Florida/{0}.png", flBackgroundIcon); ib.ImageSource = new BitmapImage(new Uri(flWeatherIcon, UriKind.Absolute)); ib.Stretch = Stretch.UniformToFill; Florida.Background = ib; } //weather info flName.Text = myWeather.name; flTemp.Text = "Temp: " + ((int)myWeather.main.temp).ToString() + " F"; flCondition.Text = myWeather.weather[0].description; flTimeUpdated.Text = "Last Updated on: " + DateTime.Now.ToShortTimeString(); //sunrise and sunset sunrise = DateTimeOffset.FromUnixTimeSeconds(myWeather.sys.sunrise); sunrise += TimeSpan.FromHours(-5); sunset = DateTimeOffset.FromUnixTimeSeconds(myWeather.sys.sunset); sunset += TimeSpan.FromHours(-5); flSunrise.Text = "sunrise: " + sunrise.ToString("hh':'mm") + " AM"; flSunset.Text = "sunset: " + sunset.ToString("hh':'mm") + " PM"; }); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed }, period); }