@@ -140,6 +140,10 @@ function errorHandler(errData: UnhandledErrorEventData) {
140140 }
141141}
142142
143+ function getVersionMaj ( ) {
144+ return parseInt ( Platform . device . osVersion . split ( "." ) [ 0 ] ) ;
145+ }
146+
143147// options - desiredAccuracy, updateDistance, minimumUpdateTime, maximumAge, timeout
144148export function getCurrentLocation ( options : Options ) : Promise < Location > {
145149 return new Promise ( function ( resolve , reject ) {
@@ -164,6 +168,7 @@ export function getCurrentLocation(options: Options): Promise<Location> {
164168 } else {
165169 let timerId ;
166170 let locListener ;
171+ let initLocation ;
167172
168173 let stopTimerAndMonitor = function ( locListenerId ) {
169174 if ( timerId !== undefined ) {
@@ -174,18 +179,30 @@ export function getCurrentLocation(options: Options): Promise<Location> {
174179 } ;
175180
176181 let successCallback = function ( location : Location ) {
177- if ( typeof options . maximumAge === "number" && location . timestamp . valueOf ( ) + options . maximumAge < new Date ( ) . valueOf ( ) ) {
178- // returned location is too old, but we still have some time before the timeout so maybe wait a bit?
179- return ;
182+ if ( getVersionMaj ( ) < 9 ) {
183+ if ( typeof options . maximumAge === "number" && location . timestamp . valueOf ( ) + options . maximumAge < new Date ( ) . valueOf ( ) ) {
184+ // returned location is too old, but we still have some time before the timeout so maybe wait a bit?
185+ return ;
186+ }
187+
188+ if ( options . desiredAccuracy !== Accuracy . any && ! initLocation ) {
189+ // regardless of desired accuracy ios returns first location as quick as possible even if not as accurate as requested
190+ initLocation = location ;
191+ return ;
192+ }
180193 }
181194
182195 stopTimerAndMonitor ( locListener . id ) ;
183196 resolve ( location ) ;
184197 } ;
185198
186- locListener = LocationListenerImpl . initWithLocationError ( successCallback ) ;
199+ locListener = LocationListenerImpl . initWithLocationError ( successCallback , reject ) ;
187200 try {
188- LocationMonitor . startLocationMonitoring ( options , locListener ) ;
201+ if ( getVersionMaj ( ) >= 9 ) {
202+ LocationMonitor . requestLocation ( options , locListener ) ;
203+ } else {
204+ LocationMonitor . startLocationMonitoring ( options , locListener ) ;
205+ }
189206 } catch ( e ) {
190207 stopTimerAndMonitor ( locListener . id ) ;
191208 reject ( e ) ;
@@ -321,6 +338,11 @@ export class LocationMonitor {
321338 return null ;
322339 }
323340
341+ static requestLocation ( options : Options , locListener : any ) : void {
342+ let iosLocManager = getIOSLocationManager ( locListener , options ) ;
343+ iosLocManager . requestLocation ( ) ;
344+ }
345+
324346 static startLocationMonitoring ( options : Options , locListener : any ) : void {
325347 let iosLocManager = getIOSLocationManager ( locListener , options ) ;
326348 iosLocManager . startUpdatingLocation ( ) ;
@@ -342,7 +364,7 @@ export class LocationMonitor {
342364 iosLocManager . distanceFilter = options ? options . updateDistance : minRangeUpdate ;
343365 locationManagers [ locListener . id ] = iosLocManager ;
344366 locationListeners [ locListener . id ] = locListener ;
345- if ( parseInt ( Platform . device . osVersion . split ( "." ) [ 0 ] ) >= 9 ) {
367+ if ( getVersionMaj ( ) >= 9 ) {
346368 iosLocManager . allowsBackgroundLocationUpdates =
347369 options && options . iosAllowsBackgroundLocationUpdates != null ?
348370 options . iosAllowsBackgroundLocationUpdates : false ;
0 commit comments