getLocation function
Implementation
Future<Position> getLocation() async {
if (!await Geolocator.isLocationServiceEnabled()) {
return Future.error(LocationErrors.locationDisabled);
}
switch (await Geolocator.checkPermission()) {
case LocationPermission.always:
return await Geolocator.getCurrentPosition();
case LocationPermission.denied:
return Future.error(LocationErrors.permissionDenied);
case LocationPermission.deniedForever:
return Future.error(LocationErrors.permissionDeniedForever);
case LocationPermission.whileInUse:
return await Geolocator.getCurrentPosition();
default:
return Future.error(LocationErrors.unknownProblem);
}
}