To keep tracking user location in my flutter app, I am using the geolocator package as follows:
LocationSettings getLocationSettings() {
LocationSettings locationSettings;
if (defaultTargetPlatform == TargetPlatform.android) {
locationSettings = AndroidSettings(
//(Optional) Set foreground notification config to keep the app alive
//when going to the background
foregroundNotificationConfig: const ForegroundNotificationConfig(
notificationText:
"Example app will continue to receive your location even when you aren't using it",
notificationTitle: "Running in Background",
));
} else if (defaultTargetPlatform == TargetPlatform.iOS) {
locationSettings = AppleSettings(
accuracy: LocationAccuracy.best,
activityType: ActivityType.automotiveNavigation,
pauseLocationUpdatesAutomatically: true,
// Only set to true if our app will be started up in the background.
showBackgroundLocationIndicator: true,
);
} else {
locationSettings = const LocationSettings(
accuracy: LocationAccuracy.best,
);
}
final positionStream = _geolocatorPlatform.getPositionStream(
locationSettings: locationSettings);
as described in geolocator documentation. Everything is working fine, I get the location updates even when the app is in the background. My question is to know whether I should see any notification, because I don't see any.
you have to
Streamthe location.this will keep show the notification and as long as the notification is displayed, your app will successfully get the GPS data.