getLastKnownPosition method
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.
- Throws a PermissionDeniedException when user has not approved access.
- Throws a LocationServiceDisabledException when the user allowed access, but the location services of the device are disabled.
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;
}
}