Пример #1
0
        private async void LoadGeoCity()
        {
            try
            {
                //get position coords of current location
                var position = await LocationManager.GetPosition();

                string tempUnit = "";
                var    x        = position.Coordinate.Point.Position.Latitude;
                var    y        = position.Coordinate.Point.Position.Longitude;

                //check if settings set up
                if (localSettings.Values["temp"] == null)
                {
                    localSettings.Values["temp"] = "metric";
                    tempUnit = "metric";
                }
                else
                {
                    tempUnit = localSettings.Values["temp"].ToString();
                }


                //get weather by location coords
                result = await WeatherProxy.GetWeatherByLocation(x, y, tempUnit);


                if (result != null)
                {
                    ProgressRing.IsActive = false;

                    SetLayout(result, tempUnit);
                }
            }
            catch (Exception e)
            {
                //write exception message
                GetForecast.IsEnabled = false;
                SearchCity.IsEnabled  = false;
                Error.Foreground      = new SolidColorBrush(Colors.Red);
                Error.Text            = e.Message.ToString();
            }
        }
Пример #2
0
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            //check passed back parameter
            if (e.Parameter is string && !string.IsNullOrWhiteSpace((string)e.Parameter))
            {
                string[] coords = e.Parameter.ToString().Split(' ');

                string tempUnit = localSettings.Values["temp"].ToString();

                //get weather root object based on coords passed back from search page
                result = await WeatherProxy.GetWeatherByLocation(double.Parse(coords[0]), double.Parse(coords[1]), tempUnit);



                SetLayout(result, tempUnit);
            }
            else
            {
                LoadGeoCity();
            }

            base.OnNavigatedTo(e);
        }