I am using XFLabs.Geolocator (https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Geolocator) in a Xamarin Forms PCL project. There is no published Nuget package for XFLabs in iOS and Android. Therefore, I read the code from Github and copy it to my PCL and iOS projects.
var geolocator = DependencyService.Get<IGeolocator>();
// geolocator.StartListening(1000, 1);
var position = geolocator.GetPositionAsync(10000).Result; // THIS LINE HAS PROBLEMS
Debug.WriteLine(position.Longitude);
Debug.WriteLine(position.Latitude);
The DependencyService works fine. I got back a geolocator like this
{MyProject.iOS.Geolocator}
DesiredAccuracy: 0
IsGeolocationAvailable: true
IsGeolocationEnabled: false // This is FALSE, is it a problem?
IsListening: false
SupportsHeading: false
However, the position assignment line always throw a TaskCanceledException. If I uncomment the geolocator.StartListening line, the position assignment line just run forever. Fyi, I have added NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription to my info.plist. Furthermore, the application never asks me for Location Permission.
Can you please help me with this problem.
Thanks so much!