Forum Xamarin.Forms

Geo location is not working in xamarin android

gdkgdk INMember ✭✭✭

Hi everyone, I am try to get the current geo location of the phone using 'plugin.geolocator' but it works fine in ios in android getting task cancellation exception. Here is the code I have tried. Please suggest any idea why I am getting this exception.

sample code:

            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = -1;

            if (locator.IsGeolocationEnabled)
                var position = await locator.GetPositionAsync(TimeSpan.FromMilliseconds(5000));

These are the permissions I have gave in android manifest file.

     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

I am getting task cancellation exception while I am testing in emulator. I have tried with changing time span but no luck getting task cancellation exception only.


Sign In or Register to comment.