getCurrentPosition static method

Future<Position> getCurrentPosition({
  1. LocationAccuracy desiredAccuracy = LocationAccuracy.best,
  2. bool forceAndroidLocationManager = false,
  3. 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 PermissionDeniedException when trying to request the device's location when the user denied access. 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,
}) =>
    GeolocatorPlatform.instance.getCurrentPosition(
      desiredAccuracy: desiredAccuracy,
      forceAndroidLocationManager: forceAndroidLocationManager,
      timeLimit: timeLimit,
    );