Windows.Devices.Geolocation Location Services Permissions Issue RRS feed

  • Question

  • Hi all,

    I am developing a Windows WPF application for Windows 10. Currently we aren't able to migrate it to UWP, but I am able to use the Windows Runtime from a Microsoft Blog Post. 

    I have been able to access the location via Windows.Devices.Geolocation and retrieve the position from the many sensors on our Windows 10 (1809) tablets. However, when I try to engage with the Windows.Devices.Geolocation.Geofencing, I get the following error:

    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    The weirdest part is, I don't see any reason why I should be able to access the Position via a PositionChanged event handler in the constructor of my Geolocator object. I've validated that the Location Services in settings are enabled and that apps can use Location. Is Geofencing a limitation of running Windows Runtime on a WPF application?

    public class LocationService
         private GeolocationAccessStatus AccessStatus { get; set; }
         public LocationService()
              var task = new Task(Init);
         private async void Init()
              AccessStatus = await Geolocator.RequestAccessAsync();
              } while (AccessStatus != GeolocationAccessStatus.Allowed && AccessStatus != GeolocationAccessStatus.Denied);
              if (AccessStatus == GeolocationAccessStatus.Denied)
                   Console.WriteLine(@"Location data has been blocked at the device level and may not be retrieved at this time.");
              GeolocatorObj = new Geolocator();
              GeolocatorObj.PositionChanged += OnPositionChange;
              GeolocatorObj.ReportInterval = 60000;
         private async void SetupGeofence()
              Console.WriteLine(@"Beginning Geofence setup process.");
              // Register the geofence
                   foreach (var item in Geofences)
                         // item.LocationGeofence is a Geofence object
                         //This is where the exception gets thrown:
                         Console.WriteLine($@"Added {LocationName} to the Geofence monitor...");
                   GeofenceMonitor.Current.StatusChanged += OnGeofenceStatusChanged;
                   GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChanged;
               catch(Exception ex)
                   Console.WriteLine(@"There was an issue adding the Geofences. Skipping for now...");

    Any clarification would be incredibly helpful and appreciated.

    • Edited by techdev4 Tuesday, March 3, 2020 10:48 PM
    Tuesday, March 3, 2020 10:46 PM