我们正在从 迁移到Flutter。我们使用这个线程在不导航到设置页面的情况下打开位置服务。
在Flutter中如何实现这一点?
当前的临时代码会导航到设置页面:
在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();
}