static Future<FlutterLocation> determinePosition() async { bool serviceEnabled; LocationPermission permission; Position p; try {到此这篇定位打开了无法获取位置安卓手机(安卓手机获取定位失败)的文章就介绍到这了,更多相关内容请继续浏览下面的相关推荐文章,希望大家都能在编程的领域有一番成就!
//这里使用的权限申请插件 ,请自行搜索相关文档配置获取依赖 PermissionStatus permissionStatus = await LocationPermissions().requestPermissions(); if(PermissionStatus.granted == permissionStatus) { // Test if location services are enabled. serviceEnabled = await Geolocator.isLocationServiceEnabled(); if (!serviceEnabled) { // Location services are not enabled don't continue // accessing the position and request users of the // App to enable the location services. return Future.error('Location services are disabled.'); } permission = await Geolocator.checkPermission(); if (permission == LocationPermission.denied) { permission = await Geolocator.requestPermission(); if (permission == LocationPermission.deniedForever) { // Permissions are denied forever, handle appropriately. return Future.error( 'Location permissions are permanently denied, we cannot request permissions.'); } if (permission == LocationPermission.denied) { // Permissions are denied, next time you could try // requesting permissions again (this is also where // Android's shouldShowRequestPermissionRationale // returned true. According to Android guidelines // your App should show an explanatory UI now. return Future.error('Location permissions are denied'); } } // p = await AMapLocationClient.getLocation(true); p = await Geolocator.getCurrentPosition(); print('location is get ${p}'); } else{ await LocationPermissions().openAppSettings(); } } catch (e) { ToastUtil.showToast('获取定位失败:$e'); } return FlutterLocation(p?.latitude, p?.longitude); }
版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/bcyy/40880.html