Exemple #1
0
        private void AsyncUpdateMapAndForecast()
        {
            UpdateMapPosition(mapPosition);
            Device.BeginInvokeOnMainThread(async() =>
            {
                currentResponse = await WeatherAPI.sharedInstance.GetWeatherByCoordinates(mapPosition.Latitude, mapPosition.Longitude);

                if (currentResponse != null)
                {
                    UpdateForecast(currentResponse);
                    UpdatePinPosition(mapPosition);
                }
            });
        }
Exemple #2
0
        public async void OnSwitchToggled(object sender, ToggledEventArgs e)
        {
            WeatherAPI.sharedInstance.units = e.Value ? WeatherAPI.Units.metric : WeatherAPI.Units.imperial;

            if (currentResponse != null)
            {
                currentResponse = await WeatherAPI.sharedInstance.GetWeatherByCoordinates(currentResponse.coord.lat, currentResponse.coord.lon);

                if (currentResponse != null)
                {
                    UpdateForecast(currentResponse);
                    UpdatePinPosition(map.Pins[0].Position);
                }
            }
        }
Exemple #3
0
        // Helpers

        private void UpdateForecast(WeatherResponse response)
        {
            if (!mainStack.Children.Contains(forecastInfo))
            {
                mainStack.Children.Insert(mainStack.Children.Count - 1, forecastInfo);
                forecastInfo.FadeTo(1);
            }

            // populate labels with data
            locationLabel.Text   = response.name;
            conditionsLabel.Text = response.weather[0].main + ", " + response.main.temp + "°";
            highLabel.Text       = response.main.temp_max + "°";
            lowLabel.Text        = response.main.temp_min + "°";
            humidityLabel.Text   = response.main.humidity + "%";
            windSpeedLabel.Text  = response.wind.speed + (WeatherAPI.sharedInstance.units == WeatherAPI.Units.imperial ? "mph" : "m/s");
            cloudCoverLabel.Text = response.clouds.all + "%";

            favoriteButton.Text = isFavorite(response.coord) ? "Remove Favorite" : "Add Favorite";
        }