GeolocatorPlugin: GetPositionAsync never returns, timesout or raises exception on first call

Bug Information

Version Number of Plugin: 4.2.0.0 Device Tested On: iPhone 5S iOS11.3 Simulator Tested On: N/A Version of VS: 2017 Version of Xamarin: 2.3.4.267 Versions of other things you are using: Xcode 9.3

Steps to reproduce the behaviour

Run the application for the first time under debug. Request position using .GetPositionAsync() Confirm the pop-up to allow permission for locations .GetPositionAsync() never returns, timesout, or throws an exception. Close app, launch again, no need for pop-up as permissions already granted, works fine

Expected Behavior

GetPositionAsync() should either turn a location, timeout or throw an exception. Have tried adding a timeout of 10s (Timespan) to the .GetPositionAsync() call and/or a cancellation token - still never returns

Actual Behavior

.GetPositionAsync() never returns

Code snippet

private async Task<bool> GetCurrentLocation()
        {
            var locator = CrossGeolocator.Current;
            locator.DesiredAccuracy = 100;
            if (!CrossGeolocator.IsSupported)
                return false;
            if (!CrossGeolocator.Current.IsGeolocationAvailable)
                return false;
            try
            {
                var position = await locator.GetPositionAsync(); // This never returns

                latitude = position.Latitude;
                longitude = position.Longitude;
                return true;
            }
            catch (Exception e)
            {
                string reason = e.Message;
                return false;
            }
        }

plist <key>NSLocationWhenInUseUsageDescription</key> <string>You are about to use location!</string> <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>You are about to use location!</string> <key>UIBackgroundModes</key> <array> <string>location</string> <string>bluetooth-central</string> </array>

Screenshots

N/A

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 22 (4 by maintainers)

Most upvoted comments

I can confirm as well. Seems to be an issue building with 11.3 SDK. Was working fine when I was building with SDK 10.2. However, now that I upgraded my Mac(build machine) to Sierra High (Mac OS 10.13). I cannot go back to 10.2 SDK. Well, I can install the SDK but get several build issues. Not important in this case though. Just know despite not being able to deploy to a device(Ad-Hoc) under 10.2. I can use the simulator and the response from the call is almost immediate. So it does work when NOT using 11.3 SDK. About to test with 11.0. However, I can assume it will not work though. Appears to be the changes to 11+. Possibly permissions. Just as stevenhawkin I followed the permission document correctly. Will let you know my findings after I try building with SDK 11. I think the difference between the original poster and myself is that I actually reach the time out. I have set it to a minute before and never was able to get the geo location when built under SDK 11.3.

Also, if you are using the simulator make sure you actually set the location in it first

If you are only using it while your app is running ONLY add the first permission.