|
|
@@ -1,6 +1,7 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Diagnostics;
|
|
|
+using Windows.ApplicationModel.ExtendedExecution;
|
|
|
using Windows.Devices.AllJoyn;
|
|
|
using Windows.Devices.Geolocation;
|
|
|
using Windows.Devices.Geolocation.Geofencing;
|
|
|
@@ -13,6 +14,7 @@ namespace Breda_Tour.Data
|
|
|
{
|
|
|
public class Gps
|
|
|
{
|
|
|
+ private ExtendedExecutionSession session;
|
|
|
private MapPage mapPage;
|
|
|
private Geolocator geolocator;
|
|
|
|
|
|
@@ -44,12 +46,13 @@ namespace Breda_Tour.Data
|
|
|
switch (accessStatus)
|
|
|
{
|
|
|
case GeolocationAccessStatus.Allowed:
|
|
|
- geolocator = new Geolocator{DesiredAccuracy = PositionAccuracy.High,MovementThreshold = 3};
|
|
|
+ geolocator = new Geolocator { DesiredAccuracy = PositionAccuracy.High, MovementThreshold = 3 };
|
|
|
// Subscribe events
|
|
|
geolocator.StatusChanged += OnStatusChanged;
|
|
|
geolocator.PositionChanged += OnPositionChanged;
|
|
|
// Get position
|
|
|
_position = await geolocator.GetGeopositionAsync();
|
|
|
+ StartLocationExtensionSession();
|
|
|
break;
|
|
|
case GeolocationAccessStatus.Denied:
|
|
|
_status = PositionStatus.NotAvailable;
|
|
|
@@ -92,5 +95,27 @@ namespace Breda_Tour.Data
|
|
|
mapPage.ShowLocaton(_position.Coordinate.Point);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private async void StartLocationExtensionSession()
|
|
|
+ {
|
|
|
+ session = new ExtendedExecutionSession();
|
|
|
+ session.Description = "Location Tracker";
|
|
|
+ session.Reason = ExtendedExecutionReason.LocationTracking;
|
|
|
+ session.Revoked += ExtendedExecutionSession_Revoked;
|
|
|
+ var result = await session.RequestExtensionAsync();
|
|
|
+ if (result == ExtendedExecutionResult.Denied)
|
|
|
+ {
|
|
|
+ Debug.Write("Denied!!!!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void ExtendedExecutionSession_Revoked(object sender, ExtendedExecutionRevokedEventArgs args)
|
|
|
+ {
|
|
|
+ if (session != null)
|
|
|
+ {
|
|
|
+ session.Dispose();
|
|
|
+ session = null;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-}
|
|
|
+}
|