本文介绍了在不导航到设置页面的情况下打开位置服务?扑镖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们正在从Flutter迁移.我们使用此线程打开定位服务上,而无需导航到设置页面
We are migrating from to Flutter. We used this thread to Turn on location services without navigating to settings page
如何在Flutter中实现这一目标?
How can this be achieved in Flutter?
导航到设置的当前临时代码:
The current temporary code that navigates to settings:
Future _getCurrentLocation() async {
Position position;
try {
position = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
} on PlatformException catch(e){
print(e.code);
if(e.code =='PERMISSION_DISABLED'){
print('Opening settings');
await openLocationSetting();
try {
position = await Geolocator().getCurrentPosition(
desiredAccuracy: LocationAccuracy.bestForNavigation);
} on PlatformException catch(e){
print(e.code);
}
}
}
setState(() {
// _center = LatLng(currentLocation['latitude'], currentLocation['longitude']);
_center = LatLng(position.latitude, position.longitude);
});
}
Future openLocationSetting() async {
final AndroidIntent intent = new AndroidIntent(
action: 'android.settings.LOCATION_SOURCE_SETTINGS',
);
await intent.launch();
}
推荐答案
您可以使用位置包,只需在AndroidManifest.xml和Info.plist文件中添加所需的权限,将在弹出窗口中询问权限.
You can use the location package, you just have to add the required permissions in your AndroidManifest.xml and Info.plist files, permission will be asked in a pop-up.
这篇关于在不导航到设置页面的情况下打开位置服务?扑镖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!