add geowatcher
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
using System;
|
||||
using CampusAppWP8.File.Setting;
|
||||
using CampusAppWP8.Model.Setting;
|
||||
using CampusAppWP8.Resources;
|
||||
using CampusAppWP8.Utility;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Resources;
|
||||
using System.Globalization;
|
||||
using System.IO.IsolatedStorage;
|
||||
using System.Threading;
|
||||
using System.Windows;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Navigation;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
using CampusAppWP8.Resources;
|
||||
using System.IO.IsolatedStorage;
|
||||
using CampusAppWP8.File.Setting;
|
||||
using CampusAppWP8.Model.Setting;
|
||||
using Windows.Devices.Geolocation;
|
||||
|
||||
|
||||
namespace CampusAppWP8
|
||||
@@ -134,6 +137,9 @@ namespace CampusAppWP8
|
||||
this.LoadSettings();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the appsettings from the store
|
||||
/// </summary>
|
||||
private void LoadSettings()
|
||||
{
|
||||
UserProfilFile userFile;
|
||||
@@ -147,7 +153,14 @@ namespace CampusAppWP8
|
||||
{
|
||||
this.UserSettingsLoaded();
|
||||
}
|
||||
|
||||
Thread thread = new Thread(new ThreadStart(Utilities.DetermineAndStoreCurrentPosition));
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load the usersettings from the store
|
||||
/// </summary>
|
||||
private void UserSettingsLoaded()
|
||||
{
|
||||
if (Settings.UserProfil.Model == null)
|
||||
@@ -161,6 +174,7 @@ namespace CampusAppWP8
|
||||
private void Application_Activated(object sender, ActivatedEventArgs e)
|
||||
{
|
||||
this.LoadSettings();
|
||||
|
||||
}
|
||||
|
||||
// Code, der ausgeführt werden soll, wenn die Anwendung deaktiviert wird (in den Hintergrund gebracht wird)
|
||||
|
||||
@@ -424,10 +424,25 @@
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="AsyncCtpLibrary_Phone">
|
||||
<HintPath>..\packages\BuiltToRoam.Core.Agent.1.0.1.5\lib\sl4-wp71\AsyncCtpLibrary_Phone.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="BuiltToRoam.Core.Agent">
|
||||
<HintPath>..\packages\BuiltToRoam.Core.Agent.1.0.1.5\lib\sl4-wp71\BuiltToRoam.Core.Agent.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="BuiltToRoam.GeoWatcher">
|
||||
<HintPath>..\packages\BuiltToRoam.GeoWatcher.1.0.1.5\lib\sl4-wp71\BuiltToRoam.GeoWatcher.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Phone.Controls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" />
|
||||
<Reference Include="Microsoft.Phone.Controls.Toolkit">
|
||||
<HintPath>..\packages\WPtoolkit.4.2012.10.30\lib\wp8\Microsoft.Phone.Controls.Toolkit.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json">
|
||||
<HintPath>..\packages\Newtonsoft.Json.4.5.11\lib\sl4-windowsphone71\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SharpZipLib.WindowsPhone7">
|
||||
<HintPath>..\packages\SharpZipLib-WP7.0.86.0.518\lib\sl4-windowsphone71\SharpZipLib.WindowsPhone7.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildExtensionsPath)\Microsoft\$(TargetFrameworkIdentifier)\$(TargetFrameworkVersion)\Microsoft.$(TargetFrameworkIdentifier).$(TargetFrameworkVersion).Overrides.targets" />
|
||||
|
||||
@@ -17,6 +17,7 @@ namespace CampusAppWP8.Pages.Mensa
|
||||
using Windows.Devices.Geolocation;
|
||||
using System.Threading.Tasks;
|
||||
using System.Globalization;
|
||||
using CampusAppWP8.Utility;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the MensaPage
|
||||
@@ -79,34 +80,16 @@ namespace CampusAppWP8.Pages.Mensa
|
||||
}
|
||||
|
||||
this.ProgressBar.Visibility = System.Windows.Visibility.Visible;
|
||||
//this.feed.LoadData();
|
||||
this.feed.LoadData();
|
||||
this.determinCurrentPosition();
|
||||
}
|
||||
|
||||
private async void determinCurrentPosition()
|
||||
private void determinCurrentPosition()
|
||||
{
|
||||
Geolocator geolocator = new Geolocator();
|
||||
geolocator.DesiredAccuracyInMeters = 50;
|
||||
string lat = string.Empty;
|
||||
string log = string.Empty;
|
||||
try
|
||||
{
|
||||
Geoposition geoposition = await geolocator.GetGeopositionAsync(
|
||||
maximumAge: TimeSpan.FromMinutes(15),
|
||||
timeout: TimeSpan.FromSeconds(10)
|
||||
);
|
||||
Utilities.DetermineAndStoreCurrentPosition();
|
||||
string lat = App.LoadFromAppState<string>("CurrentPosition.Lat");
|
||||
string log = App.LoadFromAppState<string>("CurrentPosition.Long");
|
||||
|
||||
lat = geoposition.Coordinate.Latitude.ToString(CultureInfo.InvariantCulture);
|
||||
log = geoposition.Coordinate.Longitude.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if ((uint)ex.HResult == 0x80004004)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
this.spsApi = new SpsApi();
|
||||
this.spsApi.onLoaded += new SpsApi.OnLoaded(this.ApiIsReady);
|
||||
List<UrlParamModel> parameterList = new List<UrlParamModel>();
|
||||
|
||||
@@ -14,6 +14,11 @@ namespace CampusAppWP8.Pages
|
||||
using CampusAppWP8.Resources;
|
||||
using Microsoft.Phone.Controls;
|
||||
using Microsoft.Phone.Shell;
|
||||
using Windows.Devices.Geolocation;
|
||||
using CampusAppWP8.Utility;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using System.Device.Location;
|
||||
|
||||
/// <summary>
|
||||
/// Class for the StartPage
|
||||
@@ -25,14 +30,14 @@ namespace CampusAppWP8.Pages
|
||||
/// </summary>
|
||||
public StartPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.InitializeComponent();
|
||||
ApplicationBarMenuItem menuItem1 = ApplicationBar.MenuItems[0] as ApplicationBarMenuItem;
|
||||
if (menuItem1 != null)
|
||||
{
|
||||
menuItem1.Text = AppResources.Setting_UserProfilAppBarTitle;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Method handle OrientationPage
|
||||
/// </summary>
|
||||
@@ -78,12 +83,14 @@ namespace CampusAppWP8.Pages
|
||||
ContentPanel.RowDefinitions[3].Height = new GridLength(1,GridUnitType.Star);
|
||||
ContentPanel.ColumnDefinitions[3].Width = GridLength.Auto;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void ApplicationBarMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
Uri url = new Uri(Constants.PathSetting_User, UriKind.Relative);
|
||||
NavigationService.Navigate(url);
|
||||
//Uri url = new Uri(Constants.PathSetting_User, UriKind.Relative);
|
||||
//NavigationService.Navigate(url);
|
||||
Utilities.DetermineAndStoreCurrentPosition();
|
||||
}
|
||||
|
||||
private void ApplicationBar_StateChanged(object sender, ApplicationBarStateChangedEventArgs e)
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace CampusAppWP8.Utility
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Device.Location;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
@@ -191,5 +193,71 @@ namespace CampusAppWP8.Utility
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method determine the current position of the phone
|
||||
/// </summary>
|
||||
/// <param name="accuracy">accuracy of the position in meters</param>
|
||||
/// <returns>the position of the phone</returns>
|
||||
public static GeoPosition<GeoCoordinate> DetermineCurrentPosition(uint accuracy = 50)
|
||||
{
|
||||
//Utilities.DetermineAndStoreCurrentPosition();
|
||||
GeoCoordinateWatcher watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
|
||||
bool success = watcher.TryStart(false, TimeSpan.FromMilliseconds(1000));
|
||||
GeoPosition<GeoCoordinate> geoposition = null;
|
||||
if (success)
|
||||
{
|
||||
geoposition = watcher.Position;
|
||||
}
|
||||
watcher.Stop();
|
||||
return geoposition;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method determine and store the current position of the phone
|
||||
/// </summary>
|
||||
public static void DetermineAndStoreCurrentPositionForce()
|
||||
{
|
||||
GeoPosition<GeoCoordinate> geoposition = Utilities.DetermineCurrentPosition();
|
||||
if (geoposition != null)
|
||||
{
|
||||
string lat = geoposition.Location.Latitude.ToString(CultureInfo.InvariantCulture);
|
||||
string log = geoposition.Location.Longitude.ToString(CultureInfo.InvariantCulture);
|
||||
string time = geoposition.Timestamp.Ticks.ToString();
|
||||
App.SaveToAppState<string>("CurrentPosition.Lat", lat);
|
||||
App.SaveToAppState<string>("CurrentPosition.Long", log);
|
||||
App.SaveToAppState<string>("CurrentPosition.Time", time);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Method determine and store the current position of the phone, in 15 min intcavv
|
||||
/// </summary>
|
||||
public static void DetermineAndStoreCurrentPosition()
|
||||
{
|
||||
string lat = App.LoadFromAppState<string>("CurrentPosition.Lat");
|
||||
string log = App.LoadFromAppState<string>("CurrentPosition.Long");
|
||||
string time = App.LoadFromAppState<string>("CurrentPosition.Time");
|
||||
if (lat == null || log == null || time == null || lat.Equals(string.Empty) || log.Equals(string.Empty) || time.Equals(string.Empty))
|
||||
{
|
||||
Utilities.DetermineAndStoreCurrentPositionForce();
|
||||
}
|
||||
else
|
||||
{
|
||||
long longTime = 0;
|
||||
if(!long.TryParse(time, out longTime))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DateTime expired = new DateTime(longTime).AddMinutes(15);
|
||||
if (DateTime.Now.Ticks > expired.Ticks)
|
||||
{
|
||||
|
||||
Utilities.DetermineAndStoreCurrentPositionForce();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="BuiltToRoam.Core.Agent" version="1.0.1.5" targetFramework="wp80" />
|
||||
<package id="BuiltToRoam.GeoWatcher" version="1.0.1.5" targetFramework="wp80" />
|
||||
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="wp80" />
|
||||
<package id="SharpZipLib-WP7" version="0.86.0.518" targetFramework="wp80" />
|
||||
<package id="WPtoolkit" version="4.2012.10.30" targetFramework="wp80" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user