First things first I want to call out that the app I am creating is a Windows Phone 8.1 RT Store Application (not a Silverlight application)
I am currently creating an application as part of my final year project for university as part of a team. The problem I am hitting is that for part of the application I need the ability to record an area on a map. Ie. The user walks around a specific area and we store that area for use in other parts of the application.
I currently am able to use the GPS to record the location and am able to display that accurately on a map. The area that is causing me issues is that the screen needs to be unlocked and the screen on for it to work. As soon as the phone locks the app (obviously) suspends and I am unable to record the location.
I have been looking online and have seen that the previous method for allowing an app to run behind the lock screen has been removed with Windows Phone 8.1, so my question to you is has anyone found any other ways?
Here is the code that I currently have.. I am using a dispatch timer to record the GPS every 20 seconds and then I add that location to a list that I have.
code:
public void getLoc()
{
Debug.WriteLine("Start");
startButtonEnabled = false;
stopButtonEnabled = true;
FindGPS();
dispatcherTimer.Tick += FindGPS_Event;
dispatcherTimer.Interval = new TimeSpan(0, 0, 20);
dispatcherTimer.Start();
}
private void FindGPS_Event(object sender, object o)
{
FindGPS();
}
private async Task FindGPS()
{
Debug.WriteLine("Find GPS");
try
{
Geoposition position = await geolocator.GetGeopositionAsync();
location.Longitude = position.Coordinate.Point.Position.Longitude;
location.Latitude = position.Coordinate.Point.Position.Latitude;
location.Accuracy = position.Coordinate.Accuracy;
location.GeoLocation =
new Geopoint(new BasicGeoposition() {Latitude = location.Latitude, Longitude = location.Longitude});
zoomLevel = 18;
}
catch (UnauthorizedAccessException)
{
Debug.WriteLine("No Data");
}
catch (TaskCanceledException)
{
Debug.WriteLine("Cancelled");
}
finally
{
Pushpin icon = new Pushpin()
{
Point =
new Geopoint(new BasicGeoposition()
{
Latitude = location.Latitude,
Longitude = location.Longitude
}),
Name = "Location"
};
location.IconOnMap.Add(icon);
}
}
getLoc
is called on a button press, and I have another button that stops the dispatchTimer
. The timer is needed, but the time frame is currently set for testing purposes.