예제 #1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            RootObject temp;

            try
            {
                // get position in class location manager fetches geolocation which contains current coordinates of device
                var currentPosition = await LocationManager.GetPosition();

                //fetches root object in temp variable
                temp = await WeatherAPI.GetWeatherWithCoordinates(currentPosition.Coordinate.Point.Position.Latitude, currentPosition.Coordinate.Point.Position.Longitude);
            }
            catch
            {
                temp = await WeatherAPI.GetWeatherWithCityName("Zagreb");
            }


            this.Weather.city = temp.city;
            this.Weather.list = temp.list;

            for (int i = 0; i < 17; i += 4)
            {
                this.Weather.list[i].main    = temp.list[i].main;
                this.Weather.list[0].weather = temp.list[0].weather;
            }

            CelsiusSign.Text  = "°C";
            Time0.Text        = "Time";
            Temperature0.Text = "Temperature";
            Description0.Text = "Description";
            Icon0.Text        = "Icon";

            string icon = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[0].weather[0].icon);

            CurrentIcon.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

            string icon1 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[4].weather[0].icon);

            Icon1.Source = new BitmapImage(new Uri(icon1, UriKind.Absolute));

            string icon2 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[8].weather[0].icon);

            Icon2.Source = new BitmapImage(new Uri(icon2, UriKind.Absolute));

            string icon3 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[12].weather[0].icon);

            Icon3.Source = new BitmapImage(new Uri(icon3, UriKind.Absolute));

            string icon4 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[16].weather[0].icon);

            Icon4.Source = new BitmapImage(new Uri(icon4, UriKind.Absolute));
        }
        private async void GetForecast_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var city = CityName.Text;

                RootObject temp = await WeatherAPI.GetWeatherWithCityName(city);

                //binding for all variables
                this.Weather.city = temp.city; //binding class city for fetching names inside that class
                this.Weather.list = temp.list; //binding lists for data access inside of the list

                for (int i = 0; i < 17; i += 4)
                {
                    this.Weather.list[i].main    = temp.list[i].main;
                    this.Weather.list[0].weather = temp.list[0].weather;
                }

                CelsiusSign.Text  = "°C";
                Time0.Text        = "Time";
                Temperature0.Text = "Temperature";
                Description0.Text = "Description";
                Icon0.Text        = "Icon";

                string icon = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[0].weather[0].icon);
                CurrentIcon.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

                string icon1 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[4].weather[0].icon);
                Icon1.Source = new BitmapImage(new Uri(icon1, UriKind.Absolute));

                string icon2 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[8].weather[0].icon);
                Icon2.Source = new BitmapImage(new Uri(icon2, UriKind.Absolute));

                string icon3 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[12].weather[0].icon);
                Icon3.Source = new BitmapImage(new Uri(icon3, UriKind.Absolute));

                string icon4 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[16].weather[0].icon);
                Icon4.Source = new BitmapImage(new Uri(icon4, UriKind.Absolute));
            }
            catch
            {
                ContentDialog wrongInputDialog = new ContentDialog
                {
                    Title   = "Wrong input",
                    Content = "You entered unavaibale city. Please try again.",
                    IsPrimaryButtonEnabled = true,
                    PrimaryButtonText      = "OK"
                };
                ContentDialogResult result = await wrongInputDialog.ShowAsync();
            }
        }
예제 #3
0
        private async void GetForecast_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var latitude  = Convert.ToDouble(Latitude.Text);
                var longitude = Convert.ToDouble(Longitude.Text);

                RootObject temp = await WeatherAPI.GetWeatherWithCoordinates(latitude, longitude);

                this.Weather.city = temp.city;
                this.Weather.list = temp.list;

                for (int i = 0; i < 17; i += 4)
                {
                    this.Weather.list[i].main    = temp.list[i].main;
                    this.Weather.list[0].weather = temp.list[0].weather;
                }

                CelsiusSign.Text  = "°C";
                Time0.Text        = "Time";
                Temperature0.Text = "Temperature";
                Description0.Text = "Description";
                Icon0.Text        = "Icon";

                string icon = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[0].weather[0].icon);
                CurrentIcon.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

                string icon1 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[4].weather[0].icon);
                Icon1.Source = new BitmapImage(new Uri(icon1, UriKind.Absolute));

                string icon2 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[8].weather[0].icon);
                Icon2.Source = new BitmapImage(new Uri(icon2, UriKind.Absolute));

                string icon3 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[12].weather[0].icon);
                Icon3.Source = new BitmapImage(new Uri(icon3, UriKind.Absolute));

                string icon4 = String.Format("ms-appx:///Assets/WeatherIcons/{0}.png", this.Weather.list[16].weather[0].icon);
                Icon4.Source = new BitmapImage(new Uri(icon4, UriKind.Absolute));
            }
            catch
            {
                ContentDialog wrongInputDialog = new ContentDialog
                {
                    Title   = "Wrong input",
                    Content = "You entered unreachable coordinates. Please try again.",
                    IsPrimaryButtonEnabled = true,
                    PrimaryButtonText      = "OK"
                };
                ContentDialogResult result = await wrongInputDialog.ShowAsync();
            }
        }