Skip to content

[Help Wanted]: Some devices reporting Location error {"errorCode":408,"message":""} #1669

@Keickd

Description

@Keickd

Required Reading

  • Confirmed

Plugin Version

5.0.5

Mobile operating-system(s)

  • iOS
  • Android

Device Manufacturer(s) and Model(s)

Redmi A9, Motorola G05/G06

Device operating-systems(s)

Android 10, 11, 15

What do you require assistance about?

We are not sure why this is happening, but some devices are reporting this issue. These devices send a position update every 45 minutes (the heartbeatInterval is set to 2700 seconds). For some of them, the updates alternate between success and failure, while others consistently fail with the same timeout error.

Could there be any misconfiguration causing this behavior?

These devices operate continuously, 24/7.

[Optional] Plugin Code and/or Config

@Singleton()
class LocationService implements VitalsService<LocationReport> {
  final LoggerService _logger;
  final ConfigService _configService;

  final _locationSubject = BehaviorSubject<LocationReport>();

  LocationService(this._logger, this._configService);

  @factoryMethod
  static Future<LocationService> setup(
    LoggerService logger,
    ConfigService configService,
  ) async {
    final service = LocationService(logger, configService);
    await service._init();
    return service;
  }

  Future<void> _init() async {
    final config = bg.Config(
      reset: true,
      foregroundService: true,
      geolocation: const bg.GeoConfig(
        desiredAccuracy: bg.DesiredAccuracy.high,
        disableLocationAuthorizationAlert: true,
      ),
      app: bg.AppConfig(
        heartbeatInterval: _configService
            .getInt(
              'location',
              'auto_update_seconds',
            )
            .toDouble(),
        stopOnTerminate: true,
        startOnBoot: false,
        enableHeadless: false,
        notification: bg.Notification(
          title: 'Maximiliana',
          text: 'El seguimiento de la ubicación está activo',
          smallIcon: 'mipmap/ic_notification',
        ),
      ),
      isMoving: true,
    );

    final state = await bg.BackgroundGeolocation.ready(config);

    bg.BackgroundGeolocation.onLocation(_onLocation, _onLocationError);
    bg.BackgroundGeolocation.onHeartbeat(_onHeartbeat);

    if (!state.enabled) {
      await bg.BackgroundGeolocation.start();
    }

    _logger.info(
      'LocationService',
      'Background geolocation configured',
      debugPayload: {
        'desiredAccuracy': config.geolocation?.desiredAccuracy?.name,
        'heartbeatInterval': config.app?.heartbeatInterval,
        'stopOnTerminate': config.app?.stopOnTerminate,
        'startOnBoot': config.app?.startOnBoot,
        'enableHeadless': config.app?.enableHeadless,
        'disableLocationAuthorizationAlert':
            config.geolocation?.disableLocationAuthorizationAlert,
      },
    );
  }

  void _onHeartbeat(bg.HeartbeatEvent event) {
    bg.BackgroundGeolocation.getCurrentPosition(
      timeout: 60,
    ).then(_onLocation).catchError((Object error) {
      _logger.warning(
        'LocationService',
        'Heartbeat location fetch failed',
        debugPayload: {'error': error.toString()},
      );
    });
  }

  void _onLocationError(bg.LocationError error) {
    _logger.error(
      'LocationService',
      'Location error',
      debugPayload: {'errorCode': error.code, 'message': error.message},
    );
  }

  void _onLocation(bg.Location location) {
    _locationSubject.add(
      (
        latitude: location.coords.latitude,
        longitude: location.coords.longitude,
      ),
    );
  }

  @override
  Stream<LocationReport> get stream => _locationSubject.stream;

  @override
  Map<String, dynamic> serializeInformation(LocationReport report) {
    return {
      'latitude': report.latitude,
      'longitude': report.longitude,
    };
  }

  @override
  String get publishPath => '/location';
}

[Optional] Relevant log output

Location error  {"errorCode":408,"message":""}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions