getLastKnownPosition method

  1. @override
Future<Position?> getLastKnownPosition({
  1. bool forceLocationManager = false,
})

Returns the last known position stored on the users device.

On Android you can force the plugin to use the old Android LocationManager implementation over the newer FusedLocationProvider by passing true to the forceLocationManager parameter. On iOS this parameter is ignored. When no position is available, null is returned. Throws a PermissionDeniedException when trying to request the device's location when the user denied access.

Implementation

@override
Future<Position?> getLastKnownPosition({
  bool forceLocationManager = false,
}) async {
  try {
    final parameters = <String, dynamic>{
      'forceLocationManager': forceLocationManager,
    };

    final positionMap =
        await _methodChannel.invokeMethod('getLastKnownPosition', parameters);

    return positionMap != null ? Position.fromMap(positionMap) : null;
  } on PlatformException catch (e) {
    final error = _handlePlatformException(e);

    throw error;
  }
}