55using Windows . Foundation ;
66using Plugin . Geolocator . Abstractions ;
77using System . Threading ;
8- #if ! WINDOWS_APP
98using Windows . Services . Maps ;
10- #endif
119
1210namespace 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
0 commit comments