configure method

Future<void> configure(
  1. LocationService configuration
)

Configures the LocationManager, incl. sending a notification to the Android notification system.

Configuration is done based on the LocationService. If not provided, as set of default configurations are used.

Implementation

Future<void> configure(LocationService configuration) async {
  // fast out if already configured
  if (configured) return;

  // ensured that this location manager is enable first
  await enable();

  info('Configuring $runtimeType - configuration: $configuration');
  _configured = false;

  if (Platform.isAndroid) {
    _settings = AndroidSettings(
        accuracy:
            geolocator.LocationAccuracy.values[configuration.accuracy.index],
        distanceFilter: configuration.distance.toInt(),
        forceLocationManager: true,
        intervalDuration: configuration.interval,
        // Set foreground notification config to keep the app alive when going to the background
        foregroundNotificationConfig: const ForegroundNotificationConfig(
          notificationText:
              'Background location is on to keep the CARP Mobile Sensing app up-to-date with your location. '
              'This is required for main features to work properly when the app is not in use.',
          notificationTitle: "CARP Location Service",
          enableWakeLock: true,
        ));
  } else if (Platform.isAndroid) {
    _settings = AppleSettings(
      accuracy:
          geolocator.LocationAccuracy.values[configuration.accuracy.index],
      distanceFilter: configuration.distance.toInt(),
      timeLimit: configuration.interval,
      // activityType: geolocator.ActivityType.fitness,
      pauseLocationUpdatesAutomatically: true,
      allowBackgroundLocationUpdates: true,
      // Only set to true if our app will be started up in the background.
      showBackgroundLocationIndicator: false,
    );
  } else {
    _settings = LocationSettings(
      accuracy:
          geolocator.LocationAccuracy.values[configuration.accuracy.index],
      distanceFilter: configuration.distance.toInt(),
      timeLimit: configuration.interval,
    );
  }

  info('$runtimeType - configured successfully.');
  _configured = true;
}