/// <summary> /// Shows "Find location" popup page, lets the user enter text and returns the text. /// </summary> /// <returns>entered text, or null when user canceled the popup dialog</returns> public static async Task <string> ShowAsync() { var popupPage = new FindLocationPopupPage { tcs = new TaskCompletionSource <string>() }; await popupPage.Navigation.PushPopupAsync(popupPage); return(await popupPage.tcs.Task); }
/// <summary> /// Called when toolbar button "Find location" was clicked /// </summary> /// <returns>task to wait on</returns> private async Task OnClicked_ToolbarButtonFindLocation() { string text = await FindLocationPopupPage.ShowAsync(); if (string.IsNullOrWhiteSpace(text)) { await this.DisplayAlert( Constants.AppTitle, "No location text was entered", "Cancel"); return; } IEnumerable <Xamarin.Essentials.Location> foundLocationsList = null; try { foundLocationsList = await Xamarin.Essentials.Geocoding.GetLocationsAsync(text); } catch (Exception ex) { // ignore exceptions and just log; assume that no location was found App.LogError(ex); } if (foundLocationsList == null || !foundLocationsList.Any()) { await this.DisplayAlert( Constants.AppTitle, "The location could not be found", "OK"); return; } var location = foundLocationsList.First(); var point = new MapPoint(location.Latitude, location.Longitude, location.Altitude); this.mapView.ShowFindResult(text, point); }