Beispiel #1
0
        /// <summary>
        /// </summary>
        private static async void LocationByGeocoding()
        {
            var dialogResult = await XameteoDialogs.Prompt(Resx.Resources.Geolocation_Title, Resx.Resources.Geolocation_Message, string.Empty);

            if (dialogResult.Ok == false)
            {
                return;
            }

            var userChoice = dialogResult.Text.Trim();

            if (userChoice.Length > 0)
            {
                XameteoDialogs.ShowLoading();

                try
                {
                    var googleResponse = await XameteoApp.Instance.Geocoding.Get(userChoice);

                    if (googleResponse.Status != "OK")
                    {
                        throw new InvalidOperationException(string.Format(Resx.Resources.Geolocation_Error, googleResponse.Status));
                    }

                    var geocodingResults = googleResponse.Results;

                    if (geocodingResults.Count < 1)
                    {
                        throw new InvalidOperationException(Resx.Resources.Geolocation_Zero);
                    }

                    XameteoDialogs.HideLoading();

                    if (geocodingResults.Count == 1)
                    {
                        SaveLocation(new CoordinatesAdapter(googleResponse.Results[0].GeocodingGeometry.Location));
                    }
                    else
                    {
                        XameteoDialogs.ActionSheet(
                            geocodingResults.Select(it => new ActionSheetOption(it.Address, () => SaveLocation(new CoordinatesAdapter(it.GeocodingGeometry.Location)))).ToList(),
                            Resx.Resources.Geolocation_Multiple
                            );
                    }
                }
                catch (Exception exception)
                {
                    XameteoDialogs.HideLoading();
                    XameteoDialogs.Alert(exception);
                }
            }
            else
            {
                XameteoDialogs.Alert(Resx.Resources.Geolocation_Title, Resx.Resources.Prompt_Error);
            }
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="source"></param>
        private static async void UpdateApixuKey(SettingsModel source)
        {
            var dialogResult = await XameteoDialogs.Prompt(Resources.ApixuKey_Title, Resources.ApixuKey_Message, XameteoApp.Instance.ApixuKey);

            if (dialogResult.Ok == false)
            {
                return;
            }

            var userChoice = dialogResult.Text.Trim();

            if (userChoice.Length > 0)
            {
                source.Value = userChoice;
                XameteoApp.Instance.ApixuKey = userChoice;
            }
            else if (dialogResult.Ok)
            {
                XameteoDialogs.Alert(Resources.ApixuKey_Title, Resources.Prompt_Error);
            }
        }