setLocationSettings function
Future<void>
setLocationSettings({
- bool askForPermission = true,
- String rationaleMessageForPermissionRequest = 'The app needs to access your location',
- String rationaleMessageForGPSRequest = 'The app needs to access your location',
- bool useGooglePlayServices = true,
- bool askForGooglePlayServices = false,
- bool askForGPS = true,
- bool fallbackToGPS = true,
- bool ignoreLastKnownPosition = true,
- double? expirationDuration,
- double? expirationTime,
- double fastestInterval = 500,
- double interval = 1000,
- double? maxWaitTime,
- int? numUpdates,
- LocationAccuracy accuracy = LocationAccuracy.high,
- double smallestDisplacement = 0,
- bool waitForAccurateLocation = true,
- double? acceptableAccuracy,
Update global location settings. The settings are a pass through to the LocationSettings class.
Implementation
Future<void> setLocationSettings({
/// If set to true, the user will be prompted to grant
/// permission to use location
/// if not already granted.
bool askForPermission = true,
/// The message to display to the user when asking for permission to use
/// location.
/// Only valid on Android.
/// For iOS, you have to change the permission in the Info.plist file.
String rationaleMessageForPermissionRequest =
'The app needs to access your location',
/// The message to display to the user when asking for permission to use GPS.
/// Only valid on Android.
String rationaleMessageForGPSRequest =
'The app needs to access your location',
/// If set to true, the app will use Google Play Services to request location.
/// If not available on the device, the app will fallback to GPS.
/// Only valid on Android.
bool useGooglePlayServices = true,
/// If set to true, the app will request Google Play Services to request
/// location.
/// If not available on the device, the app will fallback to GPS.
bool askForGooglePlayServices = false,
/// If set to true, the app will request GPS to request location.
/// Only valid on Android.
bool askForGPS = true,
/// If set to true, the app will fallback to GPS if Google Play Services
/// is not
/// available on the device.
/// Only valid on Android.
bool fallbackToGPS = true,
/// If set to true, the app will ignore the last known position
/// and request a fresh one
bool ignoreLastKnownPosition = true,
/// The duration of the location request.
/// Only valid on Android.
double? expirationDuration,
/// The expiration time of the location request.
/// Only valid on Android.
double? expirationTime,
/// The fastest interval between location updates.
/// In milliseconds.
/// Only valid on Android.
double fastestInterval = 500,
/// The interval between location updates.
/// In milliseconds.
double interval = 1000,
/// The maximum amount of time the app will wait for a location.
/// In milliseconds.
double? maxWaitTime,
/// The number of location updates to request.
/// Only valid on Android.
int? numUpdates,
/// The accuracy of the location request.
LocationAccuracy accuracy = LocationAccuracy.high,
/// The smallest displacement between location updates.
double smallestDisplacement = 0,
/// If set to true, the app will wait for an accurate location.
/// Only valid on Android.
bool waitForAccurateLocation = true,
/// The acceptable accuracy of the location request.
/// Only valid on Android.
double? acceptableAccuracy,
}) async {
final response = await _platform.setLocationSettings(
LocationSettings(
askForPermission: askForPermission,
rationaleMessageForPermissionRequest:
rationaleMessageForPermissionRequest,
rationaleMessageForGPSRequest: rationaleMessageForGPSRequest,
useGooglePlayServices: useGooglePlayServices,
askForGooglePlayServices: askForGooglePlayServices,
askForGPS: askForGPS,
fallbackToGPS: fallbackToGPS,
ignoreLastKnownPosition: ignoreLastKnownPosition,
expirationDuration: expirationDuration,
expirationTime: expirationTime,
fastestInterval: fastestInterval,
interval: interval,
maxWaitTime: maxWaitTime,
numUpdates: numUpdates,
accuracy: accuracy,
smallestDisplacement: smallestDisplacement,
waitForAccurateLocation: waitForAccurateLocation,
acceptableAccuracy: acceptableAccuracy,
),
);
if (response != true) throw Exception('Unable to set new location settings');
}