Ejemplo n.º 1
0
    public async void Button_GetWeather()
    {
#if WINDOWS_UWP
        var wr = await owms.GetWeather("Princeton,NJ");

        if (wr != null)
        {
            var weatherText = "The current temperature in {0} is {1}°F, with a high today of {2}° and a low of {3}°.";
            WriteLine(weatherText);
        }
#else
        WriteLine("The Weather library only works in UWP in this test app.");
#endif
    }
Ejemplo n.º 2
0
        private async Task ExecuteGetTempAsync()
        {
            if (string.IsNullOrEmpty(Location))
            {
                await CoreMethods.DisplayAlert(Resource.Resource.Error, Resource.Resource.ErrorCity, "Ok");

                return;
            }

            try
            {
                // Call the eather service and await the call
                var wr = await openWeatherMapService.GetWeather(Location);

                if (wr != null)
                {
                    WeatherInfo = wr;

                    // TEXT-TO-SPEECH INTEGRATION
                    string greeter = "";
                    // Customize the speech intro depending on the platformVoi
                    if (Device.RuntimePlatform == Device.iOS)
                    {
                        greeter = Resource.Resource.GreetingSiri;
                    }
                    if (Device.RuntimePlatform == Device.Android)
                    {
                        greeter = Resource.Resource.GreetingDroid;
                    }

                    // Build a message string to be spoken out loud
                    string weatherMessageTemplate = $"{greeter}. {Resource.Resource.VoiceMessage}";
                    string weatherMessage         = string.Format(weatherMessageTemplate, greeter, wr.Name, (int)wr.Main.Temp,
                                                                  (int)wr.Main.TempMax, (int)wr.Main.TempMin);
                    // Call the Text-to-Speech Dependency service on each platform to play the weather message with
                    // the platform's speech synthesizer
                    DependencyService.Get <ITextToSpeech>().Speak(weatherMessage);
                }
            }
            catch (Exception ex)
            {
                await CoreMethods.DisplayAlert(Resource.Resource.Error, Resource.Resource.ErrorInternet, "Ok");

                IsLoading = false;
            }
        }
Ejemplo n.º 3
0
        }//OnNavigatedTo

        //Ref https://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage(v=vs.110).aspx
        //    https://stackoverflow.com/questions/32314799/uwp-image-uri-in-application-folder
        public async void CurrentWeather()
        {
            try
            {
                var currentPosition = await GeoLocationService.GetPosition();
                RootObject myWeather = await OpenWeatherMapService.GetWeather(currentPosition.Coordinate.Point.Position.Latitude, currentPosition.Coordinate.Point.Position.Longitude);

                //Set labels
                Label0.Text = "Location";
                Label1.Text = "Description";
                Label2.Text = "Temperature";
                Label3.Text = "Wind Speed";
                Label4.Text = "Sun Rise";
                Label5.Text = "Sun Set";

                //Display weather image
                string icon = String.Format("ms-appx:///Assets/Weather/{0}.png", myWeather.weather[0].icon);
                WeatherImage.Source = new BitmapImage(new Uri(icon, UriKind.Absolute));

                //Display location
                LocationBlock.Text = myWeather.name;

                //Display weather description
                DescriptionBlock.Text = FirstCharToUpper(myWeather.weather[0].description);

                //Display temperature
                TemperatureBlock.Text = string.Format("{0}°C", myWeather.main.temp);

                //Display wind speed
                WindBlock.Text = string.Format("{0} m/s", myWeather.wind.speed);

                //Display time of sunrise and sunset
                var srTime = myMethods.getDate(myWeather.sys.sunrise);
                var ssTime = myMethods.getDate(myWeather.sys.sunset);
                var sunRise = srTime.ToString("H:mm");
                var sunSet = ssTime.ToString("H:mm");
                SunRiseBlock.Text = string.Format("{0}", sunRise);
                SunSetBlock.Text = string.Format("{0}", sunSet);
            }
            catch
            {
                WorldTidesStation.Text = "Error retrieving data";
                myMethods.EnableGPSDialog();
            }
        }//CurrentWeather