Problem with Xamarin Essentials' Location

Jassim Al Rahma 1,266 Reputation points


In the below project, I am not able to get the location details, and lat and long shows zero.

Kindly advice..


A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
4,937 questions
{count} votes

1 answer

Sort by: Most helpful
  1. JessieZhang-MSFT 7,526 Reputation points


    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:required="false" />  

    For the code behind , you can refer to the following code :

       public partial class MainPage : ContentPage  
        bool isGettingLocation;  
        public MainPage()  
        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: .

    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.