Пример #1
0
        private async void showCurrentWeather()
        {
            try
            {
                var position = await LocationManager.GetLocation();

                tlbError.Text = LocationManager.statusMessage;
                RootObject myWeather = await OpenWeatherMapProxy.GetWeather(position.Coordinate.Point.Position.Latitude, position.Coordinate.Point.Position.Longitude);

                //icon name given by API then referenced to the Assets /images folder
                tlbError.Text = "";
                string icon = String.Format("ms-appx:///Assets/images/{0}.png", myWeather.weather[0].icon);
                ImageResult.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));
                //present weather data to screen
                tlbResult_location.Text = "Your present location is : " + myWeather.name;
                tlbResult_temp.Text     = " Temp - " + (myWeather.main.temp).ToString() + "C° " + myWeather.weather[0].description;
                tlbResult_pressure.Text = " Pressure - " + (myWeather.main.pressure).ToString() + " : pascals";
                tlbResult_wind.Text     = " Wind - " + (myWeather.wind.speed).ToString() + " : mph :: " + " direction " + (myWeather.wind.deg) + "°";
                tlbResult_sunrise.Text  = " Sunrise :" + String.Format("{0:d/M/yyyy HH:mm:ss}", new System.DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(myWeather.sys.sunrise));
                tlbResult_sunset.Text   = " Sunset :" + String.Format("{0:d/M/yyyy HH:mm:ss}", new System.DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(myWeather.sys.sunset));
            }
            catch (Exception)
            {
                //something goes wrong all tables set to null
                tlbError.Text           = LocationManager.statusMessage;
                ImageResult.Source      = null;
                tlbResult_location.Text = "";
                tlbResult_temp.Text     = "";
                tlbResult_pressure.Text = "";
                tlbResult_wind.Text     = "";
                tlbResult_sunrise.Text  = "";
                tlbResult_sunset.Text   = "";
            }
        }
Пример #2
0
        private async void GetWeather_Click(object sender, RoutedEventArgs e)
        {
            string Lat, Lan;

            ProgressRing.IsActive = true;

            /*var geoLocator = new Geolocator();
             *
             * geoLocator.DesiredAccuracy = PositionAccuracy.High;
             *
             *
             *
             *
             * Geoposition pos = await geoLocator.GetGeopositionAsync();
             */
            var pos = await LocationManager.GetPosition();

            Lat = pos.Coordinate.Point.Position.Latitude.ToString();
            Lan = pos.Coordinate.Point.Position.Longitude.ToString();

            RootObject myWeather = await OpenWeatherMapProxy.GetWeather(Lat, Lan);



            City.Text      = myWeather.name + " ," + myWeather.sys.country;
            Today.Text     = "Today is: " + DateTime.Now.ToString("dd/MM/yyyy");
            LocalTime.Text = "Last updated: " + DateTime.Now.ToString("HH:mm:ss");

            //string icon = String.Format("http://openweathermap.org/img/wn/{0}.png", myWeather.weather[0].icon);
            string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);

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

            Description.Text = myWeather.weather[0].description;
            Temperature.Text = "Temperature is: " + myWeather.main.temp + " °C";
            FeelsLike.Text   = "Feels like is: " + myWeather.main.feels_like + " °C";
            Humidity.Text    = "Humidity: " + myWeather.main.humidity;



            ProgressRing.IsActive = false;
        }