如何处理"GPS"位置提供者需要ACCESS_FINE_LOCATION权限.在扑扑的应用程序中 [英] How to handle "gps" location provider requires ACCESS_FINE_LOCATION permission. in flutter apps
问题描述
我正在尝试通过在flutter中使用位置包和google-maps-flutter来获取用户位置.但是我收到一条错误消息,说"gps" location provider requires ACCESS_FINE_LOCATION permission.
我已将此代码添加到我的androidmanifest文件中
Hi I am trying to get user location by using location package and google-maps-flutter in flutter.. but I get an error that say "gps" location provider requires ACCESS_FINE_LOCATION permission.
I have added this code in my androidmanifest file
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
尽管我已经添加了该代码,但仍然出现错误.是否应该采取一些措施来防止此问题发生?
I still get an error although I have added that code..is there something that I should do to prevent this problem?
推荐答案
您应检查自己的权限状态,如果用户未授予该权限,则应请求权限.您可以使用位置插件获取请求权限.
You should check your self permission status and If it did not granted by user, you should request for permission. You could use location plugin for request permissions.
https://pub.dev/packages/location
Location location = new Location();
bool _serviceEnabled;
PermissionStatus _permissionGranted;
LocationData _locationData;
_serviceEnabled = await location.serviceEnabled();
if (!_serviceEnabled) {
_serviceEnabled = await location.requestService();
if (!_serviceEnabled) {
return;
}
}
_permissionGranted = await location.hasPermission();
if (_permissionGranted == PermissionStatus.denied) {
_permissionGranted = await location.requestPermission();
if (_permissionGranted != PermissionStatus.granted) {
return;
}
}
_locationData = await location.getLocation();
这篇关于如何处理"GPS"位置提供者需要ACCESS_FINE_LOCATION权限.在扑扑的应用程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!