getCurrentLocation static method

Future<Map<String, dynamic>> getCurrentLocation()

Implementation

static Future<Map<String,dynamic>> getCurrentLocation() async {
  Map<String,dynamic> result=Simplify.getDefaultResult();
  try{
    LocationPermission permission = await Geolocator.checkPermission();
      if (permission == LocationPermission.deniedForever) {
        result["message"]='Location permissions are permanently denied, we cannot request permissions.';
      }
      else if (permission == LocationPermission.denied) {
        permission = await Geolocator.requestPermission();
        if (permission == LocationPermission.denied) {
          result["message"]='Location permissions are denied';
        }
      }
      else{
        Position position=await Geolocator.getCurrentPosition();
        result["status"]="success";
        result["location"]={"lat":position.latitude,"lng":position.longitude,"accuracy":position.accuracy};
      }

  }
  catch(ex){
    result["message"] = Simplify.getExceptionMessage(ex);
  }
  return result;
}