Hello,
Welcome to Microsoft Q&A!
I found you didn't set the AndroidManifest.xml
correctly.
We should add the following inside of the manifest node:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
For the code behind , you can refer to the following code :
public partial class MainPage : ContentPage
{
bool isGettingLocation;
public MainPage()
{
InitializeComponent();
}
async void Button_Clicked(System.Object sender, System.EventArgs e)
{
isGettingLocation = true;
while (isGettingLocation)
{
var result = await Geolocation.GetLocationAsync(new GeolocationRequest(GeolocationAccuracy.Default, TimeSpan.FromMinutes(1)));
resultLocation.Text += $"lat: {result.Latitude}, lng: {result.Longitude}{Environment.NewLine}";
await Task.Delay(1000);
}
}
void Button1_Clicked(System.Object sender, System.EventArgs e)
{
isGettingLocation = false;
}
}
Refer: Finding Your Way with the Xamarin.Essentials Geolocation API.
And you can find the Sample code here: https://github.com/jfversluis/XFEGeolocationSample .
Best Regards,
Jessie Zhang
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Yes I set the permission as explained here:
https://learn.microsoft.com/en-us/xamarin/essentials/geolocation?tabs=ios
Is there any logs about this problem?