SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Future<LocationServiceResult> getLocation() async {
  2.   if (!await _service.serviceEnabled()) {
  3.     var serviceActive = await _service.requestService();
  4.  
  5.   if (!serviceActive)
  6.     return new LocationServiceResult(
  7.         LocationServiceStates.ServiceDisabled, null);
  8. }
  9.  
  10. /*if (!await _service.hasPermission()) {
  11.   var hasPermission = await _service.requestPermission();*/
  12. var hasAccess =
  13.     (await Permission.getPermissionsStatus([PermissionName.Location]))
  14.             .first ==
  15.         PermissionStatus.allow;
  16. if (!hasAccess) {
  17.   var p = await Permission.requestPermissions([PermissionName.Location]);
  18.   if (p != PermissionStatus.allow) {
  19.     return new LocationServiceResult(
  20.         LocationServiceStates.ServicePermissionRequired, null);
  21.   }
  22. }
  23.  
  24. var locationData = await this._service.getLocation().catchError((error) {
  25.   print(error.toString());
  26.   return new LocationServiceResult(LocationServiceStates.Error, null);
  27. });
  28.  
  29. return new LocationServiceResult(LocationServiceStates.Success,
  30.     new LatLng(locationData.latitude, locationData.longitude));
  31. }
  32. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top