public async void Run(IBackgroundTaskInstance taskInstance) { // Get a deferral, to prevent the task from closing prematurely // while asynchronous code is still running. BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); //call GetPosition var position = await GeolocationVM.GetPosition(); var lat = position.Coordinate.Latitude; var lon = position.Coordinate.Longitude; RootObject weather = await APIDataVM.GetWeather(lat, lon); string icon = String.Format("ms-appx:///Icons/{0}.png", weather.weather[0].icon.Replace("d", "").Replace("n", "")); var updater = TileUpdateManager.CreateTileUpdaterForApplication(); updater.EnableNotificationQueue(true); updater.Clear(); XmlDocument tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150PeekImage02); XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text"); tileTextAttributes[0].InnerText = weather.name; tileTextAttributes[1].InnerText = ("Tempreture : " + (((int)weather.main.temp_min) - 32).ToString() + (char)176); tileTextAttributes[2].InnerText = weather.weather[0].description; tileTextAttributes[3].InnerText = ("Speed : " + ((int)weather.wind.speed).ToString()); XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image"); ((XmlElement)tileImageAttributes[0]).SetAttribute("src", icon); ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic"); updater.Update(new TileNotification(tileXml)); // Inform the system that the task is finished. deferral.Complete(); }
public async Task PopulateWeatherDataAsync() { try { var position = await GeolocationVM.GetPosition(); var lat = position.Coordinate.Latitude; var lon = position.Coordinate.Longitude; //RootObject result = await APIDataVM.GetWeather(lat, lon); // var RootObject = await APIDataVM.GetWeatherDays(lat, lon); RootObjectDays weather = await APIDataVM.GetWeatherDays(lat, lon); var Days = new ObservableCollection <Day>(weather.list); //var Days = RootObject.list; foreach (var list in Days) { //Covert Fahreheit to celsius list.temp.min = (((int)list.temp.min) - 32); list.temp.max = (((int)list.temp.max) - 32); DayList.Add(list); } } catch (Exception) { // LocationText.Text = "Unable to access Weather"; } }
private async void Page_Loaded(object sender, RoutedEventArgs e) { try { progressRing.IsActive = true; //call GetPosition var position = await GeolocationVM.GetPosition(); var lat = position.Coordinate.Latitude; var lon = position.Coordinate.Longitude; //Call ApiManager RootObject weather = await APIDataVM.GetWeather(lat, lon); progressRing.IsActive = false; //gets icons from Assets folder - URI for acccess local resources ms-appx:/// string icon = String.Format("ms-appx:///Icons/{0}.png", weather.weather[0].icon.Replace("d", "").Replace("n", "")); ResultImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute)); /* * double conv = .5556; * int fah = (((int)weather.main.temp) - 32); * int celcius = ((int)(fah * conv)); */ TempText.Text = (((int)weather.main.temp_min) - 32).ToString() + (char)176; // TempText1.Text = celcius.ToString() + (char)176 + "C"; DescriptionText.Text = weather.weather[0].description; LocationText.Text = weather.name; // WindText.Text = ((int)weather.wind.speed).ToString(); } catch (Exception) { LocationText.Text = "Unable to access Weather"; } }