Ver código fonte

First geofencing attempt + button/route draw temporary disabled for better emu usage.

Jeroen 10 anos atrás
pai
commit
bde934e7ca

+ 6 - 5
Breda-Tour/Data/Gps.cs

@@ -1,9 +1,12 @@
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using Windows.Devices.AllJoyn;
 using Windows.Devices.Geolocation;
+using Windows.Devices.Geolocation.Geofencing;
 using Windows.System;
 using Windows.UI.Xaml;
+using Windows.UI.Xaml.Media.Animation;
 using Breda_Tour.MapScreen;
 
 namespace Breda_Tour.Data
@@ -12,6 +15,7 @@ namespace Breda_Tour.Data
     {
         private MapPage mapPage;
         private Geolocator geolocator;
+
         private Geoposition _position;
         public Geoposition Position
         {
@@ -82,13 +86,10 @@ namespace Breda_Tour.Data
 
         public async void Refresh()
         {
-            if (geolocator == null)
-            {
-                Start();
-            }
-            else
+            if (geolocator != null)
             {
                 _position = await geolocator.GetGeopositionAsync();
+                mapPage.ShowLocaton(_position.Coordinate.Point);
             }
         }
     }

+ 15 - 2
Breda-Tour/MapScreen/MapPage.xaml.cs

@@ -23,6 +23,7 @@ using Windows.UI.Xaml.Controls.Maps;
 using Windows.UI.Xaml.Shapes;
 using Breda_Tour.CustomControls;
 using System.Diagnostics;
+using Windows.Devices.Geolocation.Geofencing;
 using Windows.UI.Xaml.Automation.Peers;
 using Breda_Tour.Data;
 using Breda_Tour.RouteSelectScreen;
@@ -43,6 +44,7 @@ namespace Breda_Tour.MapScreen
 
         public MapPage()
         {
+            GeofenceMonitor.Current.GeofenceStateChanged += OnGeofenceStateChange; 
             this.NavigationCacheMode = NavigationCacheMode.Enabled;
             marker = new MapIcon();
             marker.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/Marker.png"));
@@ -62,9 +64,9 @@ namespace Breda_Tour.MapScreen
                 route = e.Parameter as Route;
                 Map.MapElements.Clear();
                 gps.History.Clear();
-                ShowLocaton(gps.Position.Coordinate.Point);
+                gps.Refresh();
                 ShowWaypoints(route);
-                ShowRoute();
+                //ShowRoute();
             }
         }
 
@@ -111,11 +113,17 @@ namespace Breda_Tour.MapScreen
         {
             await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
             {
+                GeofenceMonitor.Current.Geofences.Clear();
                 for (int x = 0; x < route.Waypoints.Count; x++)
                 {
+                    //Waypoints handeling
                     Waypoint wayp = route.Waypoints.ElementAt(x);
                     MapIcon wp = new MapIcon { Location = wayp.Position, Title = (x + 1).ToString() };
                     Map.MapElements.Add(wp);
+                    //Geofencing handeling
+                    string name = $"Fence {(x + 1).ToString()}";
+                    GeofenceMonitor.Current.Geofences.Add(new Geofence(name,new Geocircle(wayp.Position.Position,10), MonitoredGeofenceStates.Entered, true,TimeSpan.FromSeconds(3)));
+                    Debug.Write("Geofences count: "+ GeofenceMonitor.Current.Geofences.Count);
                 }
                 //foreach (var waypoint in route.WayPoints)
                 //{
@@ -161,5 +169,10 @@ namespace Breda_Tour.MapScreen
                 Map.MapElements.Add(mapPolyline);
             });
         }
+
+        private void OnGeofenceStateChange(GeofenceMonitor sender, object args)
+        {
+            Debug.Write("Kappa circle entered!!");
+        }
     }
 }

+ 1 - 4
Breda-Tour/RouteSelectScreen/RouteExample.xaml.cs

@@ -105,10 +105,7 @@ namespace Breda_Tour.RouteSelectScreen
                 ProgressRing.Visibility = Visibility.Collapsed;
                 StartButton.Visibility = Visibility.Visible;
             }
-            else
-            {
-                ShowRouteInfo();
-            }
+            StartButton.Visibility = Visibility.Visible;
         }
 
         private void Waypoints_OnItemClick(object sender, ItemClickEventArgs e)