Implemented GPS and current position
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using NavCityBreda.Helpers;
|
||||
using NavCityBreda.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -6,6 +7,7 @@ using System.Linq;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using Windows.ApplicationModel;
|
||||
using Windows.ApplicationModel.Activation;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Foundation;
|
||||
using Windows.Foundation.Collections;
|
||||
using Windows.Storage;
|
||||
@@ -25,6 +27,20 @@ namespace NavCityBreda
|
||||
/// </summary>
|
||||
sealed partial class App : Application
|
||||
{
|
||||
|
||||
public static Frame rootFrame;
|
||||
|
||||
private static GeoTracker geo = new GeoTracker();
|
||||
|
||||
public static GeoTracker Geo
|
||||
{
|
||||
get
|
||||
{
|
||||
return geo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the singleton application object. This is the first line of authored code
|
||||
/// executed, and as such is the logical equivalent of main() or WinMain().
|
||||
@@ -50,7 +66,7 @@ namespace NavCityBreda
|
||||
}
|
||||
#endif
|
||||
|
||||
Frame rootFrame = Window.Current.Content as Frame;
|
||||
rootFrame = Window.Current.Content as Frame;
|
||||
|
||||
// Do not repeat app initialization when the Window already has content,
|
||||
// just ensure that the window is active
|
||||
|
||||
+53
-10
@@ -16,13 +16,31 @@
|
||||
<Style x:Key="NavIcon" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
|
||||
<Setter Property="FontSize" Value="28" />
|
||||
<Setter Property="Margin" Value="-2,5,0,0" />
|
||||
<Setter Property="Margin" Value="0,5,0,0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="NavText" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="28" />
|
||||
<Setter Property="Margin" Value="20,0,0,0" />
|
||||
</Style>
|
||||
|
||||
|
||||
<Style x:Key="GPSInfoPanel" TargetType="StackPanel">
|
||||
<Setter Property="Orientation" Value="Horizontal" />
|
||||
<Setter Property="VerticalAlignment" Value="Center" />
|
||||
<Setter Property="Margin" Value="10,0,10,0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="GPSInfoIcon" TargetType="TextBlock">
|
||||
<Setter Property="FontFamily" Value="Segoe MDL2 Assets" />
|
||||
<Setter Property="FontSize" Value="20" />
|
||||
<Setter Property="Margin" Value="5,5,0,0" />
|
||||
</Style>
|
||||
|
||||
<Style x:Key="GPSInfoText" TargetType="TextBlock">
|
||||
<Setter Property="FontSize" Value="20" />
|
||||
<Setter Property="Margin" Value="15,0,0,0" />
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
@@ -38,14 +56,20 @@
|
||||
</RelativePanel>
|
||||
|
||||
<!-- http://stackoverflow.com/questions/32108362/uwp-swipe-to-open-splitview-pane-->
|
||||
<SplitView Grid.Row="1" Name="NavView" DisplayMode="Overlay" OpenPaneLength="300">
|
||||
<SplitView Grid.Row="1" Name="NavView" DisplayMode="Overlay" OpenPaneLength="275">
|
||||
<SplitView.Pane>
|
||||
<StackPanel Name="MySplitviewPane" VerticalAlignment="Stretch"
|
||||
HorizontalAlignment="Stretch"
|
||||
<RelativePanel Name="MySplitviewPane" VerticalAlignment="Stretch"
|
||||
ManipulationMode="TranslateX"
|
||||
ManipulationCompleted="MySplitviewPane_ManipulationCompleted">
|
||||
ManipulationCompleted="MySplitviewPane_ManipulationCompleted"
|
||||
Background="Transparent">
|
||||
|
||||
<ListBox SelectionMode="Single" Name="NavList" SelectionChanged="NavList_SelectionChanged">
|
||||
<ListBox RelativePanel.AlignTopWithPanel="True" SelectionMode="Single" Name="NavList" SelectionChanged="NavList_SelectionChanged" Tapped="NavList_Tapped">
|
||||
<ListBoxItem Name="NavListRoute">
|
||||
<StackPanel Style="{StaticResource NavStackPanel}">
|
||||
<TextBlock Style="{StaticResource NavIcon}" Text=""/>
|
||||
<TextBlock Style="{StaticResource NavText}" x:Uid="MenuItemRoute" Text="[MenuItemRoute]"/>
|
||||
</StackPanel>
|
||||
</ListBoxItem>
|
||||
<ListBoxItem Name="NavListHelp">
|
||||
<StackPanel Style="{StaticResource NavStackPanel}">
|
||||
<TextBlock Style="{StaticResource NavIcon}" Text=""/>
|
||||
@@ -59,19 +83,38 @@
|
||||
</StackPanel>
|
||||
</ListBoxItem>
|
||||
</ListBox>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel RelativePanel.AlignBottomWithPanel="True" RelativePanel.AlignLeftWithPanel="True" RelativePanel.AlignRightWithPanel="True" Background="Transparent">
|
||||
<StackPanel Style="{StaticResource GPSInfoPanel}" Tapped="GPSRefresh_Tapped">
|
||||
<TextBlock Style="{StaticResource GPSInfoIcon}" Text=""/>
|
||||
<TextBlock Style="{StaticResource GPSInfoText}" Text="{Binding Status}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Style="{StaticResource GPSInfoPanel}">
|
||||
<TextBlock Style="{StaticResource GPSInfoIcon}" Text=""/>
|
||||
<TextBlock Style="{StaticResource GPSInfoText}" Text="{Binding Source}"/>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Style="{StaticResource GPSInfoPanel}">
|
||||
<TextBlock Style="{StaticResource GPSInfoIcon}" Text=""/>
|
||||
<TextBlock Style="{StaticResource GPSInfoText}" Text="{Binding Accuracy}"/>
|
||||
</StackPanel>
|
||||
|
||||
<TextBlock Text="Nav City Breda @ 2015" Margin="15, 5"/>
|
||||
</StackPanel>
|
||||
</RelativePanel>
|
||||
</SplitView.Pane>
|
||||
<SplitView.Content>
|
||||
<Grid>
|
||||
<Frame Name="Frame"/>
|
||||
|
||||
<Grid ManipulationMode="TranslateX"
|
||||
<StackPanel ManipulationMode="TranslateX"
|
||||
ManipulationCompleted="Grid_ManipulationCompleted"
|
||||
Width="150"
|
||||
Width="10"
|
||||
Background="Transparent"
|
||||
HorizontalAlignment="Left"
|
||||
VerticalAlignment="Stretch">
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</SplitView.Content>
|
||||
</SplitView>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using NavCityBreda.Helpers;
|
||||
using NavCityBreda.ViewModel;
|
||||
using NavCityBreda.Views;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -33,6 +34,8 @@ namespace NavCityBreda
|
||||
Frame.Navigated += Frame_Navigated;
|
||||
SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;
|
||||
Frame.Navigate(typeof(MapView));
|
||||
|
||||
this.DataContext = new MenuVM();
|
||||
}
|
||||
|
||||
private void OnBackRequested(object sender, BackRequestedEventArgs e)
|
||||
@@ -53,7 +56,6 @@ namespace NavCityBreda
|
||||
{
|
||||
//Dirty Hack
|
||||
string pagename = e.SourcePageType.ToString().Split('.').Last();
|
||||
Debug.WriteLine(pagename);
|
||||
|
||||
NavList.SelectedIndex = -1;
|
||||
|
||||
@@ -76,6 +78,7 @@ namespace NavCityBreda
|
||||
break;
|
||||
case "routeview":
|
||||
PageTitle.Text = Util.Loader.GetString("PageTitleRoute");
|
||||
NavListRoute.IsSelected = true;
|
||||
break;
|
||||
case "waypointview":
|
||||
PageTitle.Text = Util.Loader.GetString("PageTitleWaypoint");
|
||||
@@ -93,18 +96,21 @@ namespace NavCityBreda
|
||||
NavView.IsPaneOpen = false;
|
||||
|
||||
if (NavListHelp.IsSelected)
|
||||
{
|
||||
Frame.Navigate(typeof(HelpView));
|
||||
}
|
||||
else if (NavListSettings.IsSelected)
|
||||
{
|
||||
Frame.Navigate(typeof(SettingsView));
|
||||
}
|
||||
else if(NavListRoute.IsSelected)
|
||||
Frame.Navigate(typeof(RouteView));
|
||||
}
|
||||
|
||||
private void NavList_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
NavView.IsPaneOpen = false;
|
||||
}
|
||||
|
||||
private void Grid_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
|
||||
{
|
||||
if (e.Cumulative.Translation.X > 50)
|
||||
if (e.Cumulative.Translation.X > 20)
|
||||
{
|
||||
NavView.IsPaneOpen = true;
|
||||
}
|
||||
@@ -112,10 +118,15 @@ namespace NavCityBreda
|
||||
|
||||
private void MySplitviewPane_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e)
|
||||
{
|
||||
if (e.Cumulative.Translation.X < -50)
|
||||
if (e.Cumulative.Translation.X < -20)
|
||||
{
|
||||
NavView.IsPaneOpen = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void GPSRefresh_Tapped(object sender, TappedRoutedEventArgs e)
|
||||
{
|
||||
App.Geo.ForceRefresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.Foundation;
|
||||
using Windows.System;
|
||||
|
||||
namespace NavCityBreda.Model
|
||||
{
|
||||
public class GeoTracker
|
||||
{
|
||||
private Geolocator geo;
|
||||
|
||||
private string status;
|
||||
public string Status { get { return status; } }
|
||||
|
||||
private Geoposition pos;
|
||||
public Geoposition Position { get { return pos; } }
|
||||
|
||||
public bool Connected { get; private set; }
|
||||
|
||||
public GeoTracker()
|
||||
{
|
||||
status = "Waiting...";
|
||||
Connected = false;
|
||||
StartTracking();
|
||||
}
|
||||
|
||||
public event TypedEventHandler<Geolocator, StatusChangedEventArgs> StatusChanged
|
||||
{
|
||||
add { if(Connected)geo.StatusChanged += value; }
|
||||
remove { geo.StatusChanged -= value; }
|
||||
}
|
||||
|
||||
public event TypedEventHandler<Geolocator, PositionChangedEventArgs> PositionChanged
|
||||
{
|
||||
add { if (Connected) geo.PositionChanged += value; }
|
||||
remove { geo.PositionChanged -= value; }
|
||||
}
|
||||
|
||||
public async void ForceRefresh()
|
||||
{
|
||||
pos = await geo.GetGeopositionAsync();
|
||||
}
|
||||
|
||||
private async void StartTracking()
|
||||
{
|
||||
// Request permission to access location
|
||||
var accessStatus = await Geolocator.RequestAccessAsync();
|
||||
|
||||
switch (accessStatus)
|
||||
{
|
||||
case GeolocationAccessStatus.Allowed:
|
||||
geo = new Geolocator {
|
||||
DesiredAccuracy = PositionAccuracy.High,
|
||||
//MovementThreshold = 1
|
||||
ReportInterval = 500
|
||||
};
|
||||
|
||||
Connected = true;
|
||||
|
||||
geo.PositionChanged += Geo_PositionChanged;
|
||||
geo.StatusChanged += Geo_StatusChanged;
|
||||
|
||||
status = "Waiting for update...";
|
||||
break;
|
||||
|
||||
case GeolocationAccessStatus.Denied:
|
||||
status = "Access Denied";
|
||||
bool result = await Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-location"));
|
||||
break;
|
||||
|
||||
default:
|
||||
case GeolocationAccessStatus.Unspecified:
|
||||
status = "Unspecified Error Occured";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
|
||||
{
|
||||
status = args.Status.ToString();
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
pos = args.Position;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,10 +90,10 @@
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<!-- A reference to the entire .Net Framework and Windows SDK are automatically included -->
|
||||
<PRIResource Include="Languages\de-DE\Resources.resw" />
|
||||
<PRIResource Include="Languages\nl-NL\Resources.resw" />
|
||||
<PRIResource Include="Strings\de-DE\Resources.resw" />
|
||||
<PRIResource Include="Strings\nl-NL\Resources.resw" />
|
||||
<None Include="project.json" />
|
||||
<PRIResource Include="Languages\en-US\Resources.resw" />
|
||||
<PRIResource Include="Strings\en-US\Resources.resw" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="App.xaml.cs">
|
||||
@@ -105,7 +105,10 @@
|
||||
<Compile Include="MainPage.xaml.cs">
|
||||
<DependentUpon>MainPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Model\GeoTracker.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModel\MapVM.cs" />
|
||||
<Compile Include="ViewModel\MenuVM.cs" />
|
||||
<Compile Include="Views\HelpView.xaml.cs">
|
||||
<DependentUpon>HelpView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace NavCityBreda.ViewModel
|
||||
{
|
||||
class MapVM : INotifyPropertyChanged
|
||||
{
|
||||
CoreDispatcher dispatcher;
|
||||
|
||||
public MapVM()
|
||||
{
|
||||
dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
|
||||
App.Geo.StatusChanged += Geo_StatusChanged;
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.UI.Core;
|
||||
|
||||
namespace NavCityBreda.ViewModel
|
||||
{
|
||||
public class MenuVM : INotifyPropertyChanged
|
||||
{
|
||||
CoreDispatcher dispatcher;
|
||||
|
||||
public MenuVM()
|
||||
{
|
||||
dispatcher = Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
|
||||
App.Geo.StatusChanged += Geo_StatusChanged;
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
|
||||
private void Geo_StatusChanged(Geolocator sender, StatusChangedEventArgs args)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Status));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
|
||||
{
|
||||
NotifyPropertyChanged(nameof(Source));
|
||||
NotifyPropertyChanged(nameof(Accuracy));
|
||||
});
|
||||
}
|
||||
|
||||
public string Status
|
||||
{
|
||||
get
|
||||
{
|
||||
return App.Geo.Status;
|
||||
}
|
||||
}
|
||||
|
||||
public string Source
|
||||
{
|
||||
get
|
||||
{
|
||||
if (App.Geo.Connected && App.Geo.Position != null)
|
||||
return App.Geo.Position.Coordinate.PositionSource.ToString();
|
||||
else
|
||||
return "N/A";
|
||||
}
|
||||
}
|
||||
|
||||
public string Accuracy
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (App.Geo.Connected && App.Geo.Position != null)
|
||||
return App.Geo.Position.Coordinate.Accuracy.ToString() + "m";
|
||||
else
|
||||
return "0m";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using NavCityBreda.ViewModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -12,6 +13,8 @@ using Windows.UI.Xaml.Data;
|
||||
using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using Windows.Devices.Geolocation;
|
||||
using Windows.UI.Xaml.Controls.Maps;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
@@ -22,10 +25,36 @@ namespace NavCityBreda.Views
|
||||
/// </summary>
|
||||
public sealed partial class MapView : Page
|
||||
{
|
||||
MapIcon CurrenPosition;
|
||||
|
||||
public MapView()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.NavigationCacheMode = NavigationCacheMode.Enabled;
|
||||
|
||||
this.DataContext = new MapVM();
|
||||
|
||||
CurrenPosition = new MapIcon();
|
||||
|
||||
App.Geo.PositionChanged += Geo_PositionChanged;
|
||||
}
|
||||
|
||||
private void Geo_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
|
||||
{
|
||||
Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
|
||||
{
|
||||
DrawCurrenPosition(new Geopoint(args.Position.Coordinate.Point.Position));
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawCurrenPosition(Geopoint p)
|
||||
{
|
||||
CurrenPosition.Location = p;
|
||||
CurrenPosition.NormalizedAnchorPoint = new Point(0.5, 1.0);
|
||||
CurrenPosition.Title = "Current Position";
|
||||
CurrenPosition.ZIndex = 999;
|
||||
|
||||
Map.MapElements.Add(CurrenPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user