getLastKnownPosition method

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

Get the best most recent location currently available.

If a location is not available, which should happen very rarely, null will be return. The best accuracy available while respecting the location permissions will be returned.

Implementation

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

    final result = await methodChannel.invokeMethod(
        Methods.getLastKnownPosition, params);
    final positionMap =
        result != null ? Map<String, dynamic>.from(result) : null;
    return positionMap != null ? Position.fromMap(positionMap) : null;
  } on PlatformException catch (e) {
    final error = _handlePlatformException(e);
    throw error;
  }
}