currentLocation method

Stream<LocationResult> currentLocation ({@required LocationAccuracy accuracy, bool inBackground: false, LocationPermission permission: const LocationPermission() })

Requests the current "one-shot" Location, using Android and iOS best practice mechanics. Automatically request location permission beforehand if not granted.

The location service will try to match the requested accuracy, but it can also return a less accurate Location as fallback.

By default, location requests are stopped when app goes to background, and resumed when app comes back to foreground. You can disable this behaviour by setting true for inBackground.

A single LocationResult will be pushed down the stream, and the stream will complete. To stop the ongoing location request, cancel the subscription.

Behaviour per platform:

  • Android: Returns the last known location if available and valid. Otherwise requests a single location update. If last known location is retrieved, no location request is started. accuracy and inBackground will be ignored.
  • iOS: Requests a single location update.

See also:

Implementation

static Stream<LocationResult> currentLocation({
  @required LocationAccuracy accuracy,
  bool inBackground = false,
  LocationPermission permission = const LocationPermission(),
}) =>
    _locationChannel.locationUpdates(new _LocationUpdatesRequest(
      _LocationUpdateStrategy.current,
      permission,
      accuracy,
      inBackground,
    ));