getCurrentPosition method

Future<Position> getCurrentPosition()

Get current coordinates

Implementation

Future<Position> getCurrentPosition() async {
  if (!await Geolocator.isLocationServiceEnabled()) {
    throw Exception('LOCATION_DISABLED');
  }

  var permission = await Geolocator.checkPermission();
  if (permission == LocationPermission.denied) {
    permission = await Geolocator.requestPermission();
    if (permission == LocationPermission.denied) {
      throw Exception('PERMISSION_DENIED');
    }
  }

  if (permission == LocationPermission.deniedForever) {
    throw Exception('PERMISSION_DENIED');
  }

  return Geolocator.getCurrentPosition();
}