-6ren">
gpt4 book ai didi

Flutter geolocator, list 中没有定义位置权限。确保 list 中至少定义了 ACCESS_FINE_LOCATION 或....

转载 作者:行者123 更新时间:2023-12-02 18:55:48 26 4
gpt4 key购买 nike

我在 flutter 中使用地理定位器,我在 list 文件中定义了权限,但它一直告诉我我没有。

list 文件:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="packagename">


<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission>ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission>ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />

地理定位器代码:

class _LoadingScreenState extends State<LoadingScreen> {

void getLocation() async{
bool serviceEnabled;
LocationPermission permission;

serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
return Future.error('Location services are disabled.');
}

permission = await Geolocator.checkPermission();
if (permission == LocationPermission.deniedForever) {
return Future.error(
'Location permissions are permantly denied, we cannot request permissions.');
}

if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission != LocationPermission.whileInUse &&
permission != LocationPermission.always) {
return Future.error(
'Location permissions are denied (actual value: $permission).');
}
}
Position position= await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(permission);
print(position);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: (){
getLocation();
},
child: Text('Get Location'),
),
),
);
}
}

我正在我的物理设备上测试该应用程序。请告诉我我应该怎么做才能让它发挥作用。

最佳答案

唯一错误的是“android.name”中的字符串。

<uses-permission android:name="android.permission>ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission>ACCESS_FINE_LOCATION" />

正确的是:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

关于Flutter geolocator, list 中没有定义位置权限。确保 list 中至少定义了 ACCESS_FINE_LOCATION 或....,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66196673/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com