private void ApplySensorData()
{
//// Do not apply sensor data if the engine is not ready yet,
//// or if it is still busy.
//if (!IsReady)
//{
// return;
//}
// Applies heading if found.
bool shouldRefreshHeading = false;
double? deviceHeading;
lock (_SyncRoot)
{
shouldRefreshHeading =
_LastKnownHeading.HasValue
&& _HasLastKnownHeadingChanged;
deviceHeading = _LastKnownHeading;
}
lock (_SyncRoot)
{
// Marks heading as refreshed.
_HasLastKnownHeadingChanged = false;
}
// Applies location if found.
bool shouldRefreshLoc = false;
GeoCoordinate deviceLoc;
lock (_SyncRoot)
{
// Do not apply sensor data if the engine is not ready yet,
// or if no location has been found yet, or if the location hasn't
// changed.
shouldRefreshLoc =
_LastKnownLocation != null
&& _HasLastKnownLocationChanged && IsReady;
deviceLoc = _LastKnownLocation;
}
if (shouldRefreshLoc)
{
// Older versions of Urwigo generated emulator detection code that reacts to 3m location accuracy.
// We're not an emulator, so let's prevent this old code from running.
double normHorizontalAcc = deviceLoc.HorizontalAccuracy == 3d ? 2.99d : deviceLoc.HorizontalAccuracy;
this.RefreshLocation(deviceLoc.Latitude, deviceLoc.Longitude, deviceLoc.Altitude, normHorizontalAcc);
}
lock (_SyncRoot)
{
// Marks location as refreshed.
_HasLastKnownLocationChanged = false;
}
// Sends a new event if something changed.
if (shouldRefreshHeading || shouldRefreshLoc)
{
RaisePlayerLocationChanged(DeviceLocation, DeviceHeading);
}
}