getCurrentLocation function
Future<Position>
getCurrentLocation(
)
Implementation
Future<Position> getCurrentLocation() async{
bool serviceEnable;
LocationPermission permission;
serviceEnable = await Geolocator.isLocationServiceEnabled();
if(!serviceEnable){
throw Exception('Location service are disable');
}
permission = await Geolocator.checkPermission();
if(permission == LocationPermission.denied){
permission = await Geolocator.requestPermission();
if(permission == LocationPermission.denied){
throw Exception('Location permissions are denied');
}
}
if(permission == LocationPermission.deniedForever){
throw Exception('Locations Permissions are permanently denied');
}
return await Geolocator.getCurrentPosition();
}