Skip to content

Commit

Permalink
Lots of changes that have been implemented or are in this change
Browse files Browse the repository at this point in the history
Fixes #71, Fixes #69, Fixes #53, Fixes #48, Fixes #43, Fixes #39, Fixes
#33, Fixes #31, Fixes #31, Fixes #23, Fixes #20, Fixes #15, Fixes #10,
Fixes #8, Fixes #7, Fixes #5, Fixes #2, Fixes #3
  • Loading branch information
jamesmontemagno committed Mar 21, 2017
1 parent 3321a5c commit ee5a51e
Show file tree
Hide file tree
Showing 26 changed files with 3,467 additions and 3,462 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## Changelog

### [4.0 - Beta]
Breaking Changes:
* Parameters have all been updated on several methods
* Remove Windows Phone 8/8.1 and Windows Store 8.1

New Features:
* Added iOS Support for Significant Changes & Deferral
* Added GetLastKnownLocation - Returns faster if cached
* Added GetAddressedForPosition - Retuns an address based on location passed in


Bug Fixes & Enhancements:
* Android Improved when GPS is available or not
* Better handling of timeouts
* Lots of small little updates and changes

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ You must set the ID_CAP_LOCATION permission.


#### License
Licensed under MIT, see license file.

This is a derivative to [Xamarin.Mobile's Geolocator](http://github.com/xamarin/xamarin.mobile) with a cross platform API and other enhancements.
//
// Copyright 2011-2013, Xamarin Inc.
Expand Down
45 changes: 4 additions & 41 deletions nuget/Plugin.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,7 @@

<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>
Easily access geolocation across Xamarin.iOS, Xamarin.Android, and Windows.

Example:
var locator = CrossGeolocator.Current;
locator.DesiredAccuracy = 100; //100 is new default

var position = await locator.GetPositionAsync (timeoutMilliseconds: 10000);

Console.WriteLine ("Position Status: {0}", position.Timestamp);
Console.WriteLine ("Position Latitude: {0}", position.Latitude);
Console.WriteLine ("Position Longitude: {0}", position.Longitude);

Easily access geolocation across Xamarin.iOS, Xamarin.Android, and Windows.
</description>
<summary>Easly access geolocation across Xamarin.iOS, Xamarin.Android, and Windows. View full project page for README
</summary>
Expand All @@ -32,7 +21,7 @@
<tags>xamarin, geolocator, geolocation, gps, pcl, xam.pcl, plugin, plugin for xamarin, windows phone, winphone, wp8, winrt, android, xamarin.forms, ios</tags>
<dependencies>
<group targetFramework="MonoAndroid10">
<dependency id="Plugin.Permissions" version="1.1.7"/>
<dependency id="Plugin.Permissions" version="1.2.1"/>
</group>
</dependencies>
</metadata>
Expand All @@ -45,33 +34,7 @@
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\portable-net45+wp80+win8+wpa81\Plugin.Geolocator.Abstractions.dll" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\portable-net45+wp80+win8+wpa81\Plugin.Geolocator.Abstractions.xml" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\portable-net45+wp80+win8+wpa81\Plugin.Geolocator.Abstractions.pdb" />

<!--Win Phone Silverlight-->
<file src="src\Geolocator.Plugin.WindowsPhone8\bin\Release\Plugin.Geolocator.dll" target="lib\wp8\Plugin.Geolocator.dll" />
<file src="src\Geolocator.Plugin.WindowsPhone8\bin\Release\Plugin.Geolocator.xml" target="lib\wp8\Plugin.Geolocator.xml" />
<file src="src\Geolocator.Plugin.WindowsPhone8\bin\Release\Plugin.Geolocator.pdb" target="lib\wp8\Plugin.Geolocator.pdb" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\wp8\Plugin.Geolocator.Abstractions.dll" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\wp8\Plugin.Geolocator.Abstractions.xml" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\wp8\Plugin.Geolocator.Abstractions.pdb" />

<!--Win Phone 81-->
<file src="src\Geolocator.Plugin.WindowsPhone81\bin\Release\Plugin.Geolocator.dll" target="lib\wpa81\Plugin.Geolocator.dll" />
<file src="src\Geolocator.Plugin.WindowsPhone81\bin\Release\Plugin.Geolocator.xml" target="lib\wpa81\Plugin.Geolocator.xml" />
<file src="src\Geolocator.Plugin.WindowsPhone81\bin\Release\Plugin.Geolocator.pdb" target="lib\wpa81\Plugin.Geolocator.pdb" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\wpa81\Plugin.Geolocator.Abstractions.dll" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\wpa81\Plugin.Geolocator.Abstractions.xml" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\wpa81\Plugin.Geolocator.Abstractions.pdb" />


<!--WinStore-->
<file src="src\Geolocator.Plugin.WindowsStore\bin\Release\Plugin.Geolocator.dll" target="lib\win8\Plugin.Geolocator.dll" />
<file src="src\Geolocator.Plugin.WindowsStore\bin\Release\Plugin.Geolocator.xml" target="lib\win8\Plugin.Geolocator.xml" />
<file src="src\Geolocator.Plugin.WindowsStore\bin\Release\Plugin.Geolocator.pdb" target="lib\win8\Plugin.Geolocator.pdb" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.dll" target="lib\win8\Plugin.Geolocator.Abstractions.dll" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\win8\Plugin.Geolocator.Abstractions.xml" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\win8\Plugin.Geolocator.Abstractions.pdb" />



<!--Xamarin.Android-->
<file src="src\Geolocator.Plugin.Android\bin\Release\Plugin.Geolocator.dll" target="lib\MonoAndroid10\Plugin.Geolocator.dll" />
<file src="src\Geolocator.Plugin.Android\bin\Release\Plugin.Geolocator.xml" target="lib\MonoAndroid10\Plugin.Geolocator.xml" />
Expand All @@ -94,7 +57,7 @@
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.xml" target="lib\UAP10\Plugin.Geolocator.Abstractions.xml" />
<file src="src\Geolocator.Plugin.Abstractions\bin\Release\Plugin.Geolocator.Abstractions.pdb" target="lib\UAP10\Plugin.Geolocator.Abstractions.pdb" />

<!--net45-->
<!--net45-->
<file src="src\Geolocator.Plugin.Net45\bin\Release\Plugin.Geolocator.dll" target="lib\net45\Plugin.Geolocator.dll" />
<file src="src\Geolocator.Plugin.Net45\bin\Release\Plugin.Geolocator.xml" target="lib\net45\Plugin.Geolocator.xml" />
<file src="src\Geolocator.Plugin.Net45\bin\Release\Plugin.Geolocator.pdb" target="lib\net45\Plugin.Geolocator.pdb" />
Expand Down
22 changes: 0 additions & 22 deletions nuget/readme.txt
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
Geolocator Readme

Changelog:
[4.0.0-beta4]
-Breaking Changes:
---Moved AllowsBackgroundLocationUpdates from IGeolocator to ListenerSettings, which is passed to StartListeningAsync.
---Moved PausesLocationUpdatesAutomatically from IGeolocator to ListenerSettings, which is passed to StartListeningAysnc.
-Other Changes:
---Added iOS support for significant change listening and update delivery deferral.
---Additional fixes for getting location on ios 9

[3.0.4]
-Breaking Changes:
---Changed StartListening and StopListening to Task that return a bool of success or failure
---New Namespace: Plugin.Geolocator
---Android API 14+ only
---Requires Compile Against Android API 23 (6.0)
-Automatically Prompt on Android for Permissions

-Enhancements:
---Automatically add needed android permissions
---Check for permissions before StartListening on Android
---UWP Support

## Android specific in your BaseActivity or MainActivity (for Xamarin.Forms) add this code:

public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
Expand Down
18 changes: 1 addition & 17 deletions src/Geolocator.Plugin.Abstractions/Position.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@

//
// Copyright 2011-2013, Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
16 changes: 0 additions & 16 deletions src/Geolocator.Plugin.Android/GeolocationContinuousListener.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,3 @@
//
// Copyright 2011-2013, Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

using System;
using System.Threading;
using Android.Locations;
Expand Down
15 changes: 0 additions & 15 deletions src/Geolocator.Plugin.Android/GeolocationSingleListener.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
//
// Copyright 2011-2013, Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using System;
using System.Threading.Tasks;
using Android.Locations;
Expand Down
17 changes: 8 additions & 9 deletions src/Geolocator.Plugin.Android/Geolocator.Plugin.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,18 @@
<HintPath>..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Plugin.Permissions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Plugin.Permissions.1.1.7\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
<Private>True</Private>
<Reference Include="Plugin.Permissions, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Plugin.Permissions.1.2.1\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
</Reference>
<Reference Include="Plugin.Permissions.Abstractions, Version=1.1.6.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Plugin.Permissions.1.1.7\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
<Private>True</Private>
<Reference Include="Plugin.Permissions.Abstractions, Version=1.2.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Plugin.Permissions.1.2.1\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Xml" />
<Reference Include="Xamarin.Android.Support.v4, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Xamarin.Android.Support.v4\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
<Private>True</Private>
<HintPath>..\packages\Xamarin.Android.Support.v4.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.v4.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand All @@ -71,7 +68,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="Resources\AboutResources.txt" />
</ItemGroup>
<ItemGroup>
Expand Down
60 changes: 20 additions & 40 deletions src/Geolocator.Plugin.Android/GeolocatorImplementation.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
//
// Copyright 2011-2013, Xamarin Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
using Plugin.Geolocator.Abstractions;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -52,16 +37,8 @@ public GeolocatorImplementation()
DesiredAccuracy = 100;
}

string[] Providers
{
get
{
if ((allProviders?.Length ?? 0) == 0)
allProviders = Manager.GetProviders(enabledOnly: false).ToArray();

return allProviders;
}
}
string[] Providers => Manager.GetProviders(enabledOnly: false).ToArray();


LocationManager Manager
{
Expand Down Expand Up @@ -98,7 +75,7 @@ public double DesiredAccuracy


/// <inheritdoc/>
public bool IsGeolocationEnabled => Providers.Any(Manager.IsProviderEnabled);
public bool IsGeolocationEnabled => Providers.Any(p => p != LocationManager.PassiveProvider && Manager.IsProviderEnabled(p));


public async Task<Position> GetLastKnownLocationAsync()
Expand All @@ -115,13 +92,13 @@ public async Task<Position> GetLastKnownLocationAsync()
bestLocation = location;
}

return bestLocation == null ? null : bestLocation.ToPosition();
return bestLocation?.ToPosition();

}

async Task<bool> CheckPermissions()
{
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Abstractions.Permission.Location).ConfigureAwait(false);
var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permissions.Abstractions.Permission.Location);
if (status != Permissions.Abstractions.PermissionStatus.Granted)
{
Console.WriteLine("Currently does not have Location permissions, requesting permissions");
Expand Down Expand Up @@ -158,11 +135,12 @@ public async Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToke

if (!IsListening)
{
var providers = Providers;
GeolocationSingleListener singleListener = null;
singleListener = new GeolocationSingleListener(Manager, (float)DesiredAccuracy, timeoutMilliseconds, Providers.Where(Manager.IsProviderEnabled),
singleListener = new GeolocationSingleListener(Manager, (float)DesiredAccuracy, timeoutMilliseconds, providers.Where(Manager.IsProviderEnabled),
finishedCallback: () =>
{
for (int i = 0; i < Providers.Length; ++i)
for (int i = 0; i < providers.Length; ++i)
Manager.RemoveUpdates(singleListener);
});

Expand All @@ -172,7 +150,7 @@ public async Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToke
{
singleListener.Cancel();

for (int i = 0; i < Providers.Length; ++i)
for (int i = 0; i < providers.Length; ++i)
Manager.RemoveUpdates(singleListener);
}, true);
}
Expand All @@ -182,17 +160,17 @@ public async Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToke
var looper = Looper.MyLooper() ?? Looper.MainLooper;

int enabled = 0;
for (int i = 0; i < Providers.Length; ++i)
for (int i = 0; i < providers.Length; ++i)
{
if (Manager.IsProviderEnabled(Providers[i]))
if (Manager.IsProviderEnabled(providers[i]))
enabled++;

Manager.RequestLocationUpdates(Providers[i], 0, 0, singleListener, looper);
Manager.RequestLocationUpdates(providers[i], 0, 0, singleListener, looper);
}

if (enabled == 0)
{
for (int i = 0; i < Providers.Length; ++i)
for (int i = 0; i < providers.Length; ++i)
Manager.RemoveUpdates(singleListener);

tcs.SetException(new GeolocationException(GeolocationError.PositionUnavailable));
Expand Down Expand Up @@ -233,7 +211,7 @@ public async Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToke
}
}

return await tcs.Task.ConfigureAwait(false);
return await tcs.Task;
}

/// <summary>
Expand Down Expand Up @@ -267,13 +245,14 @@ public async Task<bool> StartListeningAsync(TimeSpan minTime, double minDistance
if (IsListening)
throw new InvalidOperationException("This Geolocator is already listening");

listener = new GeolocationContinuousListener(Manager, minTime, Providers);
var providers = Providers;
listener = new GeolocationContinuousListener(Manager, minTime, providers);
listener.PositionChanged += OnListenerPositionChanged;
listener.PositionError += OnListenerPositionError;

Looper looper = Looper.MyLooper() ?? Looper.MainLooper;
for (int i = 0; i < Providers.Length; ++i)
Manager.RequestLocationUpdates(Providers[i], (long)minTimeMilliseconds, (float)minDistance, listener, looper);
for (int i = 0; i < providers.Length; ++i)
Manager.RequestLocationUpdates(providers[i], (long)minTimeMilliseconds, (float)minDistance, listener, looper);

return true;
}
Expand All @@ -283,10 +262,11 @@ public Task<bool> StopListeningAsync()
if (listener == null)
return Task.FromResult(true);

var providers = Providers;
listener.PositionChanged -= OnListenerPositionChanged;
listener.PositionError -= OnListenerPositionError;

for (int i = 0; i < Providers.Length; ++i)
for (int i = 0; i < providers.Length; ++i)
Manager.RemoveUpdates(listener);

listener = null;
Expand Down
4 changes: 2 additions & 2 deletions src/Geolocator.Plugin.Android/packages.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
<package id="Plugin.Permissions" version="1.1.7" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.0.1.3" targetFramework="monoandroid6" />
<package id="Plugin.Permissions" version="1.2.1" targetFramework="monoandroid60" />
<package id="Xamarin.Android.Support.v4" version="23.3.0" targetFramework="monoandroid60" />
</packages>
Loading

0 comments on commit ee5a51e

Please sign in to comment.