private async void Button_click(object sender, RoutedEventArgs e) { var position = await LocationManager.GetPosition(); RootObject myWeather = await WeatherMapProxy.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)); Result.Text = myWeather.name + " - " + myWeather.main.temp + " - " + myWeather.weather[0].description; }
//On button click to get weather private async void Button_Click(Object sender, RoutedEventArgs e) { //Call LocationManager Class Get Position Function var position = await LocationManager.GetPosition(); //Get results depending on current latitude and longitude RootObject myWeather = await App.WeatherMap.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)); LocationTextBlock.Text = "Location: " + myWeather.name; TempTextBlock.Text = "Temperature: " + ((int)(myWeather.main.temp - 273.15)).ToString() + "c"; HumidityTextBlock.Text = "Humidity: " + ((int)(myWeather.main.humidity)).ToString(); WindTextBlock.Text = "Wind Speed: " + ((int)(myWeather.wind.speed * 3.6)).ToString() + "km/h"; WeatherTextBlock.Text = "Weather: " + myWeather.weather[0].description; }
private async void Celsius_Click(object sender, RoutedEventArgs e) { var position = await LocationManager.GetPosition(); RootObject MyWeather = await OpenWeatherProxy.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)); NameTb.Text = MyWeather.name; TempTb.Text = "Temp: " + MyWeather.main.temp; DescTb.Text = MyWeather.weather[0].description; var din = MyWeather.dt; System.DateTime Date = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); Date = Date.AddSeconds(din); dayTb.Text = "Date: " + Date.ToString("dd-MM-yyyy"); }
private async void Page_Loaded(object sender, RoutedEventArgs e) { #region -Fetch weather data from API- var position = await LocationManager.GetPosition(); RootObjectF Forecast = await WeatherForecast.Forecast(position.Coordinate.Latitude, position.Coordinate.Longitude, 5); #endregion #region -Creating and binding into weather list- List <DayWeather> WeatherList = new List <DayWeather>(); foreach (var tempDayWeather in Forecast.list) { DayWeather Dw = new DayWeather(); Dw.Icon = String.Format("ms-appx:///Assets/Weather/{0}.png", tempDayWeather.weather[0].icon); Dw.Description = tempDayWeather.weather[0].description + " | "; Dw.Temp = tempDayWeather.temp.min.ToString() + " / " + tempDayWeather.temp.max.ToString(); System.DateTime tDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc); Dw.WeatherDate = tDate.AddSeconds(tempDayWeather.dt).ToString("dd-MMM") + " | "; WeatherList.Add(Dw); } WeatherListB.ItemsSource = WeatherList; #endregion }