getCurrentPosition static method
Future<Position>
getCurrentPosition({
- LocationAccuracy desiredAccuracy = LocationAccuracy.best,
- bool forceAndroidLocationManager = false,
- Duration? timeLimit,
Returns the current position taking the supplied desiredAccuracy
into
account.
You can control the precision of the location updates by supplying the
desiredAccuracy
parameter (defaults to "best"). On Android you can
force the use of the Android LocationManager instead of the
FusedLocationProvider by setting the forceAndroidLocationManager
parameter to true. The timeLimit
parameter allows you to specify a
timeout interval (by default no time limit is configured).
Throws a TimeoutException when no location is received within the
supplied timeLimit
duration.
Throws a LocationServiceDisabledException when the user allowed access,
but the location services of the device are disabled.
Implementation
static Future<Position> getCurrentPosition({
LocationAccuracy desiredAccuracy = LocationAccuracy.best,
bool forceAndroidLocationManager = false,
Duration? timeLimit,
}) {
late LocationSettings locationSettings;
if (defaultTargetPlatform == TargetPlatform.android) {
locationSettings = AndroidSettings(
accuracy: desiredAccuracy,
forceLocationManager: forceAndroidLocationManager,
timeLimit: timeLimit,
);
} else {
locationSettings = LocationSettings(
accuracy: desiredAccuracy,
timeLimit: timeLimit,
);
}
return GeolocatorPlatform.instance
.getCurrentPosition(locationSettings: locationSettings);
}