Proper handling of getCurrentPosition results and errors.
Your Environment
- Plugin version: 4.15.2
- Platform: Android
- OS version: 14 (API 34) (googlePlayServicesLocationVersion 21.0.1)
- Device manufacturer / model: multiple android phones (Samsung, Xiaomi, Motorola)
- React Native version (react-native -v): 0.73.6
- Plugin config
autoSync: false,
allowIdenticalLocations: true,
desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_NAVIGATION,
distanceFilter: 0,
stopDetectionDelay: 5,
stopTimeout: 5,
locationTimeout: 30,
debug: true,
disableMotionActivityUpdates: true,
disableStopDetection: true,
pausesLocationUpdatesAutomatically: false,
activityType: BackgroundGeolocation.ACTIVITY_TYPE_OTHER_NAVIGATION,
locationsOrderDirection: 'ASC',
logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
maxDaysToPersist: 1,
maxRecordsToPersist: 0,
stopOnTerminate: false,
startOnBoot: false,
foregroundService: true,
enableHeadless: true,
heartbeatInterval: 60,
preventSuspend: true,
notification: {
channelName: 'BG',
},
showsBackgroundLocationIndicator: true,
Expected Behavior
try {
const cfg = {timeout: 5, desiredAccuracy: 100, maximumAge: 15000, persist: false, samples: 1};
const loc = await BackgroundGeolocation.getCurrentPosition(cfg);
} catch(e) {
...
}
Should return location not older then maximumAge, with desiredAccuracy close to specified timeout. Or fail with thrown error. (Or at least return null / empty object)
onLocation events while handling getCurrentPosition might/should contain sample flag. (https://transistorsoft.github.io/react-native-background-geolocation/interfaces/location.html#sample)
Actual Behavior
Scenario 1: in specific conditions getCurrentPosition call never returns (nor throws error), Error 408 - Location timeout
Scenario 2: returns cached location with age older then configured maximumAge
Did not see sample flag in onLocation - location events.
Steps to Reproduce
SCENARIO 1 - Hard to reproduce, need some time for Location provider to discard caches prior test (seems like 8+ hours)
- turn off network access / turn on GPS, but without or poor GPS signal
- call getCurrentPosition
SCENARIO 2
- turn off GPS
- call getCurrentPosition
Test app repo: https://github.com/ezwaydev/BGTest
Debug logs
Logs: Scenario 1 - NETWORK OFF & GPS OFF, getCurrentPosition call throws Error
TSLocationManager W [c.t.l.l.TSLocationManager a]
‼️ Could not fetch last location
TSLocationManager D [c.t.l.u.LocationAuthorization withPermission]
ℹ️ LocationAuthorization: Permission granted
ReactNativeJS E getSingleLocation failed:1
TSLocationManager W [c.t.l.l.SingleLocationRequest finish]
⚠️ 📍 SingleLocationRequest TIMEOUT: 2
TSLocationManager W [c.t.l.l.TSLocationManager onLocationError]
⚠️ TSLocationManager received location error: 408
TSLocationManager W [c.t.l.a.BackgroundGeolocation _onLocationError]
⚠️ Location error: 408
ReactNativeJS I [onLocation] ERROR:408
Logs: Scenario 1 - NETWORK OFF & GPS ON, getCurrentPosition never returns nor throws
TSLocationManager W [c.t.l.l.TSLocationManager a]
‼️ Could not fetch last location
TSLocationManager D [c.t.l.u.LocationAuthorization withPermission]
ℹ️ LocationAuthorization: Permission granted
TSLocationManager D [c.t.l.service.AbstractService a]
🎾 start [LocationRequestService startId: 1, eventCount: 1]
TSLocationManager I [c.t.l.l.SingleLocationRequest startUpdatingLocation]
🔵 [SingleLocationRequest start, action: 2, requestId: 4]
TSLocationManager D [c.t.l.service.AbstractService a]
⚙️︎ FINISH [LocationRequestService startId: 1, eventCount: 0, sticky: true]
TSLocationManager W [c.t.l.l.SingleLocationRequest finish]
⚠️ 📍 SingleLocationRequest TIMEOUT: 4
TSLocationManager W [c.t.l.l.TSLocationManager onLocationError]
⚠️ TSLocationManager received location error: 408
TSLocationManager W [c.t.l.a.BackgroundGeolocation _onLocationError]
⚠️ Location error: 408
ReactNativeJS I [onLocation] ERROR:408
TSLocationManager D [c.t.l.service.AbstractService b]
🎾 STOP [LocationRequestService startId: 2, eventCount: 1]
TSLocationManager D [c.t.l.service.AbstractService a]
⚙️︎ FINISH [LocationRequestService startId: 2, eventCount: 0, sticky: false]
TSLocationManager D [c.t.l.service.AbstractService f]
⚙️︎ LocationRequestService.stopSelfResult(2): true
TSLocationManager D [c.t.l.service.AbstractService onDestroy]
🔴 LocationRequestService stopped
Logs: Scenario 2
TSLocationManager I [c.t.l.l.TSLocationManager a]
╔═════════════════════════════════════════════
║ getCurrentPosition LocationResult: 5 (26210ms old)
╠═════════════════════════════════════════════
╟─ 📍 Location[fused 48.148728,17.112803 hAcc=11.455 et=+45d18h11m43s286ms alt=189.5 vAcc=1.0], time: 1713190902978
TSLocationManager D [c.t.l.l.TSLocationManager a] Median accuracy: 11.4415
TSLocationManager I [c.t.l.u.LocationAuthorization withPermission]
🔵 LocationAuthorization: Requesting permission
ReactNativeJS I [onLocation] {"extras":{},"battery":{"level":0.58,"is_charging":true},"activity":{"confidence":100,"type":"still"},"is_moving":false,"age":26235,"uuid":"da047710-25df-4d21-b265-fde51880373f","odometer":0,"coords":{"age":26242,"ellipsoidal_altitude":189.5,"altitude":189.5,"altitude_accuracy":1,"heading_accuracy":45,"heading":-1,"speed":-1,"accuracy":11.5,"longitude":17.1128034,"speed_accuracy":1.5,"latitude":48.1487283},"timestamp":"2024-04-15T14:21:42.978Z"}
TSLocationManager I [c.t.l.u.LocationAuthorization$j onPermissionGranted]
✅ LocationAuthorization: Permission granted
TSLocationManager W [c.t.l.l.SingleLocationRequest finish]
⚠️ 📍 SingleLocaitonRequest ERROR: 1
TSLocationManager I [c.t.l.l.SingleLocationRequest finish]
🔵 Found previous sample
TSLocationManager I [c.t.l.l.TSLocationManager a]
╔═════════════════════════════════════════════
║ getCurrentPosition LocationResult: 5 (26249ms old)
╠═════════════════════════════════════════════
╟─ 📍 Location[fused 48.148728,17.112803 hAcc=11.455 et=+45d18h11m43s286ms alt=189.5 vAcc=1.0 {Bundle[{persist=false}]}], time: 1713190902978
TSLocationManager I [c.t.l.l.TSLocationManager onSingleLocationResult]
🔵 Acquired current position
TSLocationManager D [c.t.l.l.TSLocationManager a] Median accuracy: 11.455
ReactNativeJS I getSingleLocation acquired location:{"extras":{},"battery":{"level":0.58,"is_charging":true},"activity":{"confidence":100,"type":"still"},"is_moving":false,"age":26253,"uuid":"c648887f-2d27-49e4-991f-61c644a0b3cf","odometer":0,"coords":{"age":26256,"ellipsoidal_altitude":189.5,"altitude":189.5,"altitude_accuracy":1,"heading_accuracy":45,"heading":-1,"speed":-1,"accuracy":11.5,"longitude":17.1128034,"speed_accuracy":1.5,"latitude":48.1487283},"timestamp":"2024-04-15T14:21:42.978Z"}
ReactNativeJS W Location too old: 26253ms
ReactNativeJS I [onLocation] {"extras":{},"battery":{"level":0.58,"is_charging":true},"activity":{"confidence":100,"type":"still"},"is_moving":false,"age":26253,"uuid":"c648887f-2d27-49e4-991f-61c644a0b3cf","odometer":0,"coords":{"age":26256,"ellipsoidal_altitude":189.5,"altitude":189.5,"altitude_accuracy":1,"heading_accuracy":45,"heading":-1,"speed":-1,"accuracy":11.5,"longitude":17.1128034,"speed_accuracy":1.5,"latitude":48.1487283},"timestamp":"2024-04-15T14:21:42.978Z"}