Hi,
I am creating an application which is required location service. In the android MainActivity.cs I had written the code which display the popup location service.
In the xamarin shared program (App.xaml.cs) I had written the code to get the current location which is called in OnStart function.
Now the program is executing before user allows the permission of location service.
How can I wait to executing the program till user allows the permission.
Following is my code in xamarin shared program (App.xaml.cs)
protected override void OnStart() { MessagingCenter.Send<App, string>((App)App.Current, "OneMessage", ""); getGPSLocationCurrent(); } public async void getGPSLocationCurrent() { try { var lblLat = ""; var lblLong = ""; var lblAlt = ""; var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 100; var location = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); if (location != null) { lblLat += location.Latitude.ToString(); lblLong += location.Longitude.ToString(); lblAlt += location.Altitude.ToString(); } App.gblLatitude = lblLat; App.gblLongitude = lblLong; App.gblAltitude = lblAlt; return; } catch (FeatureNotSupportedException fnsEx) { // Handle not supported on device exception // await DisplayAlert("Alert", fnsEx.Message.ToString(), "OK"); return; } catch (PermissionException pEx) { // Handle permission exception // await DisplayAlert("Alert", pEx.Message.ToString(), "OK"); return; } catch (Exception ex) { // Unable to get location // await DisplayAlert("Alert", ex.Message.ToString(), "OK"); return; } }