transistorsoft / flutter_background_geolocation

Sophisticated, battery-conscious background-geolocation & geofencing with motion-detection
https://www.transistorsoft.com/shop/products/flutter-background-geolocation
Other
650 stars 241 forks source link

[Android] getCurrentPosition timeout #1352

Closed millerf closed 2 months ago

millerf commented 2 months ago

Your Environment

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /Users/millerf/Library/Android/sdk • Platform android-34, build-tools 34.0.0 • Java binary at: /Users/millerf/Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 17.0.11+0-17.0.11b1207.24-11852314) • All Android licenses accepted.

* Plugin config:
```dart

 bg.Config(
        desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
        distanceFilter: 50.0,
        enableHeadless: false,
        stopOnTerminate: false,
        allowIdenticalLocations: false,
        useSignificantChangesOnly: false,
        startOnBoot: true,
        foregroundService: true,
        autoSync: false,
        maxRecordsToPersist: 0,
        debug: settings.test,
        showsBackgroundLocationIndicator: false,
        persistMode: bg.Config.PERSIST_MODE_NONE,
        locationAuthorizationRequest: Platform.isIOS ? 'Always' : 'Any',
        disableLocationAuthorizationAlert: true,
        locationAuthorizationAlert: {
          'titleWhenNotEnabled':
              localizations(context).locationServiceNotEnabledInTheBackground,
          'titleWhenOff': localizations(context).locationServiceOff,
          'instructions': localizations(context).locationServiceOffInstructions,
          'cancelButton': localizations(context).cancel,
          'settingsButton': localizations(context).settings,
        },
        backgroundPermissionRationale: bg.PermissionRationale(
          title: localizations(context).locationPermissionRationaleTitle,
          message: localizations(context).locationPermissionRationaleMessage,
          positiveAction:
              localizations(context).locationPermissionRationalePositiveAction,
          negativeAction: localizations(context).cancel,
        ),
        logLevel: settings.test
            ? bg.Config.LOG_LEVEL_VERBOSE
            : bg.Config.LOG_LEVEL_OFF,
        reset: true);

Expected Behavior

Actual Behavior

Steps to Reproduce

1. 2. 3. 4.

Context

I notice a discrepancy between iOS and Android, and wanted to bring it to your attention. It might be a misperception on my side. I default to getCurrentPosition() when I am starting my app and the plugin did not return a location yet. I notice the "issue" because I thought the timeout was in milliseconds and used getCurrentPosition(timeout: 3000). And I was not sure why my app seemed stalled. For some reason it seems the timeout is actually a "timer", and the function does not return a location before the timer runs out: I know removed the 3000 to a 1, and the app works as expected. Also, I did only notice this on Android, and not on iOS, so I was wondering if there might be an issue with the way the timeout is handled...

Anyway, it might be nothing, but I wanted to bring it to your attention: getCurrentPosition doesn't seem to return anything before the timeout run out, even if a location is perfectly available...

Thanks!

christocracy commented 2 months ago

Plugin version: lastest

Please post the exact version. Consult your pubspec.yaml.

You’re having an issue with .getCurrentPosition but you’ve not posted the code you’re using or the context of when you’re calling it relative to .ready(config).

you must wait for .ready(config) to resolve before calling any method which requests location.

millerf commented 2 months ago

Plugin version

flutter_background_geolocation: ^4.15.5

you must wait for .ready(config) to resolve before calling any method which requests location.

Yes, there might be an issue here. I'll have a look later and otherwise post a more detailed code to replicate. Thanks!

millerf commented 2 months ago

It seems indeed the issue was ready() was not finished to be called. Thanks for your help.

Closing this.