Beispiel #1
0
        private async Task OnSearchButtonClicked(object args)
        {
            try
            {
                if (IsBusy)
                {
                    return;
                }

                IsBusy = true;
                IsBorderedEntryEnabled = false;
                WeatherRoot weatherRoot = null;
                var         unit        = Units.Metric;

                if (Longitude == null || Latitude == null)
                {
                    IsWarningReadVisible    = true;
                    IsWarningMessageVisible = true;
                    Warning = "Fields cannot be empty";
                    IsBorderedEntryEnabled = true;
                    IsBusy = false;
                    return;
                }

                double lat = ConvertToDouble(Latitude);
                double lon = ConvertToDouble(Longitude);
                weatherRoot = await WeatherService.GetWeather(lon, lat, unit);

                Temperature            = $"{weatherRoot?.MainWeather?.Temperature ?? 0}°";
                IsBusy                 = false;
                IsBorderedEntryEnabled = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e);
                Temperature            = "(400) Bad Request.";
                IsBorderedEntryEnabled = true;
                IsBusy = false;
            }
        }
Beispiel #2
0
        private async Task OnObtainButtonClicked(object args)
        {
            try
            {
                if (IsBusy)
                {
                    return;
                }

                IsBusy = true;
                WeatherRoot weatherRoot = null;

                if (IsGeolocationEnabled())
                {
                    var unit  = Units.Metric;
                    var local = await CrossGeolocator.Current.GetPositionAsync(10000);

                    Latitude    = local.Latitude.ToString();
                    Longitude   = local.Longitude.ToString();
                    weatherRoot = await WeatherService.GetWeather(local.Latitude, local.Longitude, unit);

                    Temperature = $"{weatherRoot?.MainWeather?.Temperature ?? 0}°";
                    IsBusy      = false;
                }
                else
                {
                    IsBusy = false;
                    return;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("Exception: " + e);
                Temperature = "(400) Bad Request.";
                IsBusy      = false;
            }
        }