Forum Xamarin.Forms


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Xamarin.Essentials Geolocation doesn't work in Android 9

nnovalbosnnovalbos Member ✭✭✭


I'm trying get my device current position though Xamarin.essentials.

I'm using the Microsoft documentation's code:

    var request = new GeolocationRequest(GeolocationAccuracy.Medium);
    var location = await Geolocation.GetLocationAsync(request);

    if (location != null)
        Console.WriteLine($"Latitude: {location.Latitude}, Longitude: {location.Longitude}, Altitude: {location.Altitude}");
catch (FeatureNotSupportedException fnsEx)
    // Handle not supported on device exception
catch (FeatureNotEnabledException fneEx)
    // Handle not enabled on device exception
catch (PermissionException pEx)
    // Handle permission exception
catch (Exception ex)
    // Unable to get location

This code works fine on Android 8 and iOS 12 but on Android 9 I never get the location.

Also I've used other method, in witch you can configure a time out for get the location, but on Android 9, when time expire, location is null.

Has anyone else had this issue? Any idea what is happening?



  • LandLuLandLu Member, Xamarin Team Xamurai

    Have you added the permissions as the documentation said:
    I've tried it on the Android 9.0 emulator the location could be obtained successfully.
    Did it fail on your particular device or each testing devices?
    Moreover, have you tried the GetLastKnownLocationAsync? It will be faster than doing a full query.

  • nnovalbosnnovalbos Member ✭✭✭

    Hello @LandLu ,

    I added permissions.

    I have this problem with a real device. On a emulator I have obtained location successfully.

    I will try to get more physical devices with Android 9, to see if the result is the same or is something of this device


  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Are you getting an exception or does the method just return null?

  • nnovalbosnnovalbos Member ✭✭✭

    Hello @JoeManke

    The method return null if I put time out in the GeolocationRequest.

    If I don't put timeout, it stays waiting indefinitely

  • LandLuLandLu Member, Xamarin Team Xamurai

    It seems your device refuses to return the location information.
    Can other location apps work on this particular device?
    You'd better try other devices to test that.

  • nnovalbosnnovalbos Member ✭✭✭


    Yes, the device refused to return the location information. I don´t know why, because location is enabled in the device.

    But when I used google maps (first time on device), google maps ask me for location permissions, I accepted and then when i go back to my app, this feature works....

    I'm confusing... i will try reset the device for reproduce this situation

    Thanks for all.

  • LandLuLandLu Member, Xamarin Team Xamurai

    @nnovalbos It seems your application hasn't turned it on. Or there's something with it on your device.
    Have you checked it on other devices or emulators?

  • nnovalbosnnovalbos Member ✭✭✭

    @LandLu On Emulators it works perfectly.
    I will try get another device with Android 9. When I have done the test, I will post my results


  • TepcoTepco Member ✭✭

    After much playing around I got Geolocation to work on my smartphone (I had to change the target platform to Android 8.0) but I note, with dismay, that Android is only accurate to within 100 meters. I want to measure shorter distances than that. Is there another option short of relying exclusively on IPhones or Windows devices?

Sign In or Register to comment.