Skip to content

Commit 67c6ccd

Browse files
Update tests & fix UWP api key requirement
1 parent 140223f commit 67c6ccd

File tree

22 files changed

+478
-406
lines changed

22 files changed

+478
-406
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## Changelog
22

3-
### [4.0 - Beta]
3+
### [4.0]
44
Breaking Changes:
55
* Parameters have all been updated on several methods
66
* Remove Windows Phone 8/8.1 and Windows Store 8.1
7-
* Now .NEt Standard Library
7+
* Now .NET Standard Library
88

99
New Features:
1010
* Added iOS Support for Significant Changes & Deferral

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ Build Status: [![Build status](https://ci.appveyor.com/api/projects/status/nan2c
1414

1515
**Platform Support**
1616

17-
Version 3.X
18-
19-
|Platform|Version|
20-
| ------------------- | :------------------: |
21-
|Xamarin.iOS|iOS 7+|
22-
|Xamarin.iOS Unified|iOS 7+|
23-
|Xamarin.Android|API 14+|
24-
|Windows Phone Silverlight|8.0+|
25-
|Windows Phone RT|8.1+|
26-
|Windows Store RT|8.1+|
27-
|Windows 10 UWP|10+|
28-
2917
Version 4.X
3018

3119
|Platform|Version|
@@ -41,7 +29,7 @@ Version 4.X
4129

4230
### API Usage
4331

44-
Below is API usage for 4.0+. To find 3.0 documentation please go [here](https://github.com/jamesmontemagno/Xamarin.Plugins/tree/0eed56ff8e9bbc4585fc60042da9cd74799b2f86/Geolocator).
32+
Below is API usage for 4.0+.
4533

4634
Call **CrossGeolocator.Current** from any project or PCL to gain access to APIs.
4735

@@ -71,7 +59,8 @@ catch(Exception ex)
7159
In addition to taking in a timespan ```GetPositionAsync``` also takes in a cancelation token.
7260

7361
#### Get Cached Location
74-
On iOS, Android, and macOS you can auery the last known position really fast by getting the cached position of the system.
62+
On iOS, Android, tvOS, and macOS you can auery the last known position really fast by getting the cached position of the system.
63+
On UWP ths will always return null.
7564

7665
```csharp
7766
var cached = await CrossGeolocator.Current.GetLastKnownLocationAsync();
@@ -126,12 +115,12 @@ private void Current_PositionChanged(object sender, Plugin.Geolocator.Abstractio
126115

127116

128117
#### Reverse Geocoding
129-
Retrieve addresses for position (4.0+)
118+
UWP will require a map key: https://docs.microsoft.com/en-us/windows/uwp/maps-and-location/authentication-key
130119

131120
```csharp
132121
try
133122
{
134-
var addresses = await locator.GetAddressesForPositionAsync (position);
123+
var addresses = await locator.GetAddressesForPositionAsync (position, string mapKey = null);
135124
var address = addresses.FirstOrDefault();
136125

137126
if(address == null)

nuget/Plugin.nuspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
<dependency id="NETStandard.Library" version="1.6.1" />
3333
</group>
3434
<group targetFramework="MonoAndroid10">
35-
<dependency id="Plugin.Permissions" version="2.0.0.30-beta"/>
35+
<dependency id="Plugin.Permissions" version="2.0.1"/>
3636
</group>
3737
<group targetFramework="Xamarin.iOS10">
38-
<dependency id="Plugin.Permissions" version="2.0.0.30-beta"/>
38+
<dependency id="Plugin.Permissions" version="2.0.1"/>
3939
</group>
4040
<group targetFramework="Xamarin.Mac20">
4141
</group>

nuget/readme.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ Geolocator Readme
22

33
For latest changes: https://github.com/jamesmontemagno/GeolocatorPlugin/blob/master/CHANGELOG.md
44

5+
## News
6+
- Plugins have moved to .NET Standard and have some important changes! Please read my blog:
7+
http://motzcod.es/post/162402194007/plugins-for-xamarin-go-dotnet-standard
8+
9+
10+
## Android
11+
You must set your app to compile against API 25 or higher and be able to install the latest android support libraries.
12+
513
## Android specific in your BaseActivity or MainActivity (for Xamarin.Forms) add this code:
614

715
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)

src/Geolocator.Plugin.Abstractions/IGeolocator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ public interface IGeolocator
6767
/// Retrieve addresses for position.
6868
/// </summary>
6969
/// <param name="position">Desired position (latitude and longitude)</param>
70+
/// <param name="mapKey">Map Key required only on UWP</param>
7071
/// <returns>Addresses of the desired position</returns>
71-
Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position);
72+
Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position, string mapKey = null);
7273

7374
/// <summary>
7475
/// Start listening for changes

src/Geolocator.Plugin.Android/Geolocator.Plugin.Android.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@
4747
<HintPath>..\packages\Plugin.CurrentActivity.1.0.1\lib\MonoAndroid10\Plugin.CurrentActivity.dll</HintPath>
4848
<Private>True</Private>
4949
</Reference>
50-
<Reference Include="Plugin.Permissions, Version=2.0.0.30, Culture=neutral, processorArchitecture=MSIL">
51-
<HintPath>..\packages\Plugin.Permissions.2.0.0.30-beta\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
50+
<Reference Include="Plugin.Permissions, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
51+
<HintPath>..\packages\Plugin.Permissions.2.0.1\lib\MonoAndroid10\Plugin.Permissions.dll</HintPath>
5252
</Reference>
5353
<Reference Include="Plugin.Permissions.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
54-
<HintPath>..\packages\Plugin.Permissions.2.0.0.30-beta\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
54+
<HintPath>..\packages\Plugin.Permissions.2.0.1\lib\MonoAndroid10\Plugin.Permissions.Abstractions.dll</HintPath>
5555
</Reference>
5656
<Reference Include="System" />
5757
<Reference Include="System.Core" />

src/Geolocator.Plugin.Android/GeolocatorImplementation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public async Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToke
223223
/// </summary>
224224
/// <param name="position">Desired position (latitude and longitude)</param>
225225
/// <returns>Addresses of the desired position</returns>
226-
public async Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position)
226+
public async Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position, string mapKey = null)
227227
{
228228
if (position == null)
229229
return null;

src/Geolocator.Plugin.Android/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="Plugin.CurrentActivity" version="1.0.1" targetFramework="monoandroid60" />
4-
<package id="Plugin.Permissions" version="2.0.0.30-beta" targetFramework="monoandroid70" />
4+
<package id="Plugin.Permissions" version="2.0.1" targetFramework="monoandroid70" />
55
<package id="Xamarin.Android.Support.Annotations" version="25.3.1" targetFramework="monoandroid70" />
66
<package id="Xamarin.Android.Support.Compat" version="25.3.1" targetFramework="monoandroid70" />
77
<package id="Xamarin.Build.Download" version="0.4.5" targetFramework="monoandroid70" />

src/Geolocator.Plugin.UWP/GeolocatorImplementation.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
using Windows.Foundation;
66
using Plugin.Geolocator.Abstractions;
77
using System.Threading;
8-
#if !WINDOWS_APP
98
using Windows.Services.Maps;
10-
#endif
119

1210
namespace Plugin.Geolocator
1311
{
@@ -21,7 +19,9 @@ public class GeolocatorImplementation : IGeolocator
2119
double desiredAccuracy;
2220
Windows.Devices.Geolocation.Geolocator locator = new Windows.Devices.Geolocation.Geolocator();
2321

24-
22+
/// <summary>
23+
/// Constructor for Implementation
24+
/// </summary>
2525
public GeolocatorImplementation()
2626
{
2727
DesiredAccuracy = 100;
@@ -49,7 +49,7 @@ public bool IsGeolocationAvailable
4949
{
5050
get
5151
{
52-
PositionStatus status = GetGeolocatorStatus();
52+
var status = GetGeolocatorStatus();
5353

5454
while (status == PositionStatus.Initializing)
5555
{
@@ -68,7 +68,7 @@ public bool IsGeolocationEnabled
6868
{
6969
get
7070
{
71-
PositionStatus status = GetGeolocatorStatus();
71+
var status = GetGeolocatorStatus();
7272

7373
while (status == PositionStatus.Initializing)
7474
{
@@ -104,10 +104,9 @@ public double DesiredAccuracy
104104
/// This is usually cached and best to display first before querying for full position.
105105
/// </summary>
106106
/// <returns>Best and most recent location or null if none found</returns>
107-
public Task<Position> GetLastKnownLocationAsync()
108-
{
109-
return Task.Factory.StartNew<Position>(()=> { return null; });
110-
}
107+
public Task<Position> GetLastKnownLocationAsync() =>
108+
Task.Factory.StartNew<Position>(()=> { return null; });
109+
111110

112111
/// <summary>
113112
/// Gets position async with specified parameters
@@ -147,7 +146,7 @@ public Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToken? can
147146
tcs.SetResult(GetPosition(op.GetResults()));
148147
break;
149148
case AsyncStatus.Error:
150-
Exception ex = op.ErrorCode;
149+
var ex = op.ErrorCode;
151150
if (ex is UnauthorizedAccessException)
152151
ex = new GeolocationException(GeolocationError.Unauthorized, ex);
153152

@@ -164,33 +163,35 @@ public Task<Position> GetPositionAsync(TimeSpan? timeout, CancellationToken? can
164163
/// </summary>
165164
/// <param name="position">Desired position (latitude and longitude)</param>
166165
/// <returns>Addresses of the desired position</returns>
167-
#if !WINDOWS_APP
168-
public async Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position)
169-
#else
170-
public Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position)
171-
#endif
166+
public async Task<IEnumerable<Address>> GetAddressesForPositionAsync(Position position, string mapKey = null)
172167
{
173-
#if !WINDOWS_APP
168+
174169
if (position == null)
175170
return null;
176171

172+
if(string.IsNullOrWhiteSpace(mapKey) && string.IsNullOrWhiteSpace(MapService.ServiceToken))
173+
{
174+
System.Diagnostics.Debug.WriteLine("Map API key is required on UWP to reverse geolocate.");
175+
return null;
176+
}
177+
178+
if (!string.IsNullOrWhiteSpace(mapKey))
179+
MapService.ServiceToken = mapKey;
180+
177181
var queryResults =
178182
await MapLocationFinder.FindLocationsAtAsync(
179-
new Geopoint(new BasicGeoposition { Latitude = position.Latitude, Longitude = position.Longitude }));
183+
new Geopoint(new BasicGeoposition { Latitude = position.Latitude, Longitude = position.Longitude })).AsTask();
180184

181185
return queryResults?.Locations.ToAddresses();
182-
#else
183-
return Task.FromResult<IEnumerable<Address>>(null);
184-
#endif
185186
}
186187

187-
/// <summary>
188+
/// <summary>
188189
/// Start listening for changes
189190
/// </summary>
190-
/// <param name="minimumTime">Time</param>
191-
/// <param name="minimumDistance">Distance</param>
191+
/// <param name="minTime">Time</param>
192+
/// <param name="minDistance">Distance</param>
192193
/// <param name="includeHeading">Include heading or not</param>
193-
/// <param name="listenerSettings">Optional settings (iOS only)</param>
194+
/// <param name="settings">Optional settings (iOS only)</param>
194195
public Task<bool> StartListeningAsync(TimeSpan minTime, double minDistance, bool includeHeading = false, ListenerSettings settings = null)
195196
{
196197

src/Geolocator.Plugin.iOSUnified/Geolocator.Plugin.iOS.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,26 +43,26 @@
4343
<Compile Include="Properties\AssemblyInfo.cs" />
4444
</ItemGroup>
4545
<ItemGroup>
46-
<Reference Include="Plugin.Permissions, Version=2.0.0.30, Culture=neutral, processorArchitecture=MSIL">
47-
<HintPath>..\packages\Plugin.Permissions.2.0.0.30-beta\lib\Xamarin.iOS10\Plugin.Permissions.dll</HintPath>
46+
<Reference Include="Plugin.Permissions, Version=2.0.1.0, Culture=neutral, processorArchitecture=MSIL">
47+
<HintPath>..\packages\Plugin.Permissions.2.0.1\lib\Xamarin.iOS10\Plugin.Permissions.dll</HintPath>
4848
</Reference>
4949
<Reference Include="Plugin.Permissions.Abstractions, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
50-
<HintPath>..\packages\Plugin.Permissions.2.0.0.30-beta\lib\Xamarin.iOS10\Plugin.Permissions.Abstractions.dll</HintPath>
50+
<HintPath>..\packages\Plugin.Permissions.2.0.1\lib\Xamarin.iOS10\Plugin.Permissions.Abstractions.dll</HintPath>
5151
</Reference>
5252
<Reference Include="System" />
5353
<Reference Include="System.Xml" />
5454
<Reference Include="System.Core" />
5555
<Reference Include="Xamarin.iOS" />
5656
</ItemGroup>
57+
<ItemGroup>
58+
<None Include="packages.config" />
59+
</ItemGroup>
5760
<ItemGroup>
5861
<ProjectReference Include="..\Geolocator.Plugin.Abstractions\Geolocator.Plugin.Abstractions.csproj">
59-
<Project>{4e7c1811-8caa-42fd-9a61-5777f611edfb}</Project>
62+
<Project>{d8a817f4-a999-4bae-8fbf-fcf86ddf9990}</Project>
6063
<Name>Geolocator.Plugin.Abstractions</Name>
6164
</ProjectReference>
6265
</ItemGroup>
63-
<ItemGroup>
64-
<None Include="packages.config" />
65-
</ItemGroup>
6666
<Import Project="..\Geolocator.Shared\Geolocator.Shared.projitems" Label="Shared" />
6767
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
6868
</Project>

0 commit comments

Comments
 (0)