getCurrentPosition method

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

Get a single current location fix on the device.

Unlike getLastKnownPosition that returns a cached location, this method could cause active location computation on the device. If the device location can be determined within reasonable time(tens of seconds), otherwise null will be return

Implementation

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

    final result = await methodChannel.invokeMapMethod<String, dynamic>(
        Methods.getCurrentPosition, params);

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