transistorsoft / flutter_background_geolocation

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

Can not get location data every 5 second #1315

Open salehrezaie opened 1 week ago

salehrezaie commented 1 week ago

Your Environment

import 'dart:async'; import 'package:delivery/bloc/auth_bloc.dart'; import 'package:flutter_background_geolocation/flutter_background_geolocation.dart' as bg; import 'package:permission_handler/permission_handler.dart';

class GeoLocationCHandler { static Future init() async { // Request permissions await Permission.locationAlways.request(); await Permission.locationWhenInUse.request(); await Permission.activityRecognition.request();

// Subscribe to location events
bg.BackgroundGeolocation.onLocation((bg.Location location) {
  AuthBloc().sendLocationData(data: location);
  print('[onLocation] - $location');
}, (bg.LocationError error) {
  print('[onLocation] ERROR - $error');
});

// Subscribe to motion change events
bg.BackgroundGeolocation.onMotionChange((bg.Location location) {
  print('[onMotionChange] - $location');
});

// Subscribe to activity change events
bg.BackgroundGeolocation.onActivityChange((bg.ActivityChangeEvent event) {
  print('[onActivityChange] - $event');
});

// Subscribe to provider change events
bg.BackgroundGeolocation.onProviderChange((bg.ProviderChangeEvent event) {
  print('[onProviderChange] - $event');
});

// Subscribe to HTTP events
bg.BackgroundGeolocation.onHttp((bg.HttpEvent response) {
  print('[onHttp] - $response');
});

// Configure the plugin
await bg.BackgroundGeolocation.ready(bg.Config(
  desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH,
  distanceFilter: 0.0,
  locationUpdateInterval: 5000, // 5 seconds
  fastestLocationUpdateInterval: 5000, // 5 seconds
  heartbeatInterval: 5, // 5 seconds
  stopOnTerminate: false,
  startOnBoot: true,
  debug: true,
  logLevel: bg.Config.LOG_LEVEL_VERBOSE,
));

// Start the plugin
bg.BackgroundGeolocation.start();

} }


## Expected Behavior
<!--- Tell us what should happen -->
Despite setting the location update interval to 5 seconds, the location data does not seem to update as expected. It would be great if you could provide guidance on how to achieve periodic location updates every 5 seconds and ensure the data is sent to the server reliably.

## Actual Behavior
<!--- Tell us what happens instead -->
Don't response location in every 5 second, and when I use my function inside heartbeat, I have it, but the location is not getting update

## Steps to Reproduce
<!--- reproduce this issue; include code to reproduce, if relevant -->
1.
2.
3.
4.

## Context
<!--- What were you trying to do? -->

## Debug logs
<!-- include iOS / Android logs
- ios XCode logs,
- use #getLog #emailLog methods (@see docs)
- Android: $ adb logcat -s TSLocationManager
-->
<details>
    <summary>Logs</summary>

``` <!-- syntax-highligting:  DO NOT REMOVE -->
I/TSLocationManager(27596): ║ ⏰ OneShot event fired: HEARTBEAT
I/TSLocationManager(27596): ╠═════════════════════════════════════════════
I/TSLocationManager(27596): [c.t.l.s.TSScheduleManager oneShot] 
I/TSLocationManager(27596):   ⏰ Scheduled OneShot: HEARTBEAT in 5000ms (jobID: -1307475748)
D/TSLocationManager(27596): [c.t.l.service.HeartbeatService onHeartbeat] ❤️
I/TSLocationManager(27596): [c.t.l.http.HttpService flush] 
W/TSLocationManager(27596):   ⚠️  Response: 403, Forbidden
I/flutter (27596): [onHttp] - [HttpEvent {success: false, status: 403, responseText: <html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1256"><title>AT1-9(2...}]
D/TSLocationManager(27596): [c.t.l.d.s.SQLiteLocationDAO unlock] 
D/TSLocationManager(27596):   ✅  UNLOCKED: d4b28770-5fcb-4e40-9449-29ed0fcf116b
I/TSLocationManager(27596): [c.t.l.u.BackgroundTaskManager$Task stop] ⏳ stopBackgroundTask: 102

christocracy commented 1 week ago

TSLocationManager(27596): ⚠️ Response: 403, Forbidden

Do you know what that means?

you’ll never get the location “every 5 seconds” while the device is stationary. The fastest heartbeat time will operate while stationary is 60s.

read the wiki “Philosophy of Operation”.