【发布时间】:2019-06-21 05:01:45
【问题描述】:
我们正在从 Flutter 迁移。我们用这个线程来Turn on location services without navigating to settings page
这在 Flutter 中如何实现?
导航到设置的当前临时代码:
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();
}
【问题讨论】:
-
查看simple_permissions 包。
标签: dart geolocation flutter location