Skip to content

Commit

Permalink
android app GPS-tracking improvements;
Browse files Browse the repository at this point in the history
  • Loading branch information
Admin authored and Admin committed Jul 28, 2018
1 parent c5809ab commit 8c95217
Show file tree
Hide file tree
Showing 16 changed files with 33 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<HintPath>..\..\packages\Xamarin.Forms.2.5.0.121934\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Java.Interop" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="Mono.Android" />
<Reference Include="mscorlib" />
Expand Down Expand Up @@ -98,29 +99,20 @@
<HintPath>..\..\packages\PInvoke.Windows.Core.0.5.64\lib\portable-net45+win8+wpa81\PInvoke.Windows.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.CurrentActivity, Version=1.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
<Private>True</Private>
<Reference Include="Plugin.CurrentActivity, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.CurrentActivity.2.1.0.2\lib\monoandroid44\Plugin.CurrentActivity.dll</HintPath>
</Reference>
<Reference Include="Plugin.DeviceInfo, Version=3.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugin.DeviceInfo.3.0.2\lib\MonoAndroid10\Plugin.DeviceInfo.dll</HintPath>
</Reference>
<Reference Include="Plugin.DeviceInfo.Abstractions, Version=3.0.2.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugin.DeviceInfo.3.0.2\lib\MonoAndroid10\Plugin.DeviceInfo.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Plugin.Geolocator, Version=4.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Libs\Xamarin.Plugins.Geolocator\android\Plugin.Geolocator.dll</HintPath>
</Reference>
<Reference Include="Plugin.Geolocator.Abstractions, Version=4.1.3.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\Libs\Xamarin.Plugins.Geolocator\android\Plugin.Geolocator.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Plugin.Permissions, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.Permissions.2.2.1\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
<Reference Include="Plugin.Geolocator, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Xam.Plugin.Geolocator.4.5.0.6\lib\monoandroid71\Plugin.Geolocator.dll</HintPath>
</Reference>
<Reference Include="Plugin.Permissions.Abstractions, Version=2.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.Permissions.2.2.1\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
<Reference Include="Plugin.Permissions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\..\packages\Plugin.Permissions.3.0.0.12\lib\monoandroid71\Plugin.Permissions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionName="First" package="lazurite.lazurite" android:versionCode="139">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="auto" android:versionName="First" package="lazurite.lazurite" android:versionCode="145">
<uses-sdk android:minSdkVersion="15" android:targetSdkVersion="26" />
<application android:label="Lazurite" android:icon="@drawable/splashscreen"></application>
<receiver android:name=".StartLazuriteServiceReceiver" android:enabled="true" android:exported="true">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<package id="PInvoke.Kernel32" version="0.5.64" targetFramework="monoandroid71" />
<package id="PInvoke.NCrypt" version="0.5.64" targetFramework="monoandroid71" />
<package id="PInvoke.Windows.Core" version="0.5.64" targetFramework="monoandroid71" />
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid71" />
<package id="Plugin.Permissions" version="2.2.1" targetFramework="monoandroid80" />
<package id="Plugin.CurrentActivity" version="2.1.0.2" targetFramework="monoandroid80" />
<package id="Plugin.Permissions" version="3.0.0.12" targetFramework="monoandroid80" />
<package id="System.AppContext" version="4.3.0" targetFramework="monoandroid71" />
<package id="System.Collections" version="4.3.0" targetFramework="monoandroid71" />
<package id="System.Collections.Concurrent" version="4.3.0" targetFramework="monoandroid71" />
Expand Down Expand Up @@ -69,6 +69,7 @@
<package id="System.Xml.XmlDocument" version="4.3.0" targetFramework="monoandroid71" />
<package id="Validation" version="2.4.15" targetFramework="monoandroid71" />
<package id="Xam.Plugin.DeviceInfo" version="3.0.2" targetFramework="monoandroid80" />
<package id="Xam.Plugin.Geolocator" version="4.5.0.6" targetFramework="monoandroid80" />
<package id="Xamarin.Android.Support.Animated.Vector.Drawable" version="25.4.0.2" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Annotations" version="25.4.0.2" targetFramework="monoandroid71" />
<package id="Xamarin.Android.Support.Compat" version="25.4.0.2" targetFramework="monoandroid71" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,39 @@ public class GeolocationListener: IGeolocationListener

public Geolocation LastGeolocation { get; private set; } = Geolocation.Empty;

private Task<bool> IsLocationAvailable() => CrossGeolocator.Current.CheckPermissionsAsync();
private bool IsLocationAvailable() => CrossGeolocator.Current.IsGeolocationAvailable && CrossGeolocator.Current.IsGeolocationEnabled;

public void StartListenChanges()
{
if (!_started)
if (!_started && IsLocationAvailable())
{
_started = true;
IsLocationAvailable().ContinueWith((isLocationAvailable) =>
{
try
{
if (isLocationAvailable.Result)
CrossGeolocator.Current.PositionChanged -= Current_PositionChanged;
CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
CrossGeolocator.Current.GetLastKnownLocationAsync().ContinueWith((t) =>
{
CrossGeolocator.Current.PositionChanged -= Current_PositionChanged;
CrossGeolocator.Current.PositionChanged += Current_PositionChanged;
CrossGeolocator.Current.GetLastKnownLocationAsync().ContinueWith((t) =>
{
if (t.Result != null)
LastGeolocation = new Geolocation(t.Result.Latitude, t.Result.Longitude, t.Result.Source == LocationSource.GPS);
});
CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromMinutes(10)).ContinueWith((t) =>
if (t.Result != null)
LastGeolocation = new Geolocation(t.Result.Latitude, t.Result.Longitude, true);
});
CrossGeolocator.Current.GetPositionAsync(TimeSpan.FromMinutes(10)).ContinueWith((t) =>
{
if (t.Result != null)
LastGeolocation = new Geolocation(t.Result.Latitude, t.Result.Longitude, true);
});
CrossGeolocator.Current.StartListeningAsync(
minimumTime: TimeSpan.FromMinutes(2),
minimumDistance: GeolocationMetersMinimumDistance,
listenerSettings: new ListenerSettings()
{
if (t.Result != null)
LastGeolocation = new Geolocation(t.Result.Latitude, t.Result.Longitude, t.Result.Source == LocationSource.GPS);
ActivityType = ActivityType.Other
});
CrossGeolocator.Current.StartListeningAsync(
minimumTime: TimeSpan.FromMinutes(2),
minimumDistance: GeolocationMetersMinimumDistance,
listenerSettings: new ListenerSettings()
{
ActivityType = ActivityType.Fitness
});
}
}
catch (Exception e)
{
Log.Error("Error while initializing GeolocationDataHandler", e);
}
});
}
}

Expand All @@ -74,7 +68,7 @@ public void Stop()
private void Current_PositionChanged(object sender, PositionEventArgs e)
{
if (e.Position.Accuracy <= 100)
LastGeolocation = new Geolocation(e.Position.Latitude, e.Position.Longitude, e.Position.Source == LocationSource.GPS);
LastGeolocation = new Geolocation(e.Position.Latitude, e.Position.Longitude, true);
}
}
}
Loading

0 comments on commit 8c95217

Please sign in to comment.