Flutter 如何获得谷歌位置服务对话框按钮的回拨点击';什么在飘动?
我需要在我的Flatter应用程序中获取设备的当前位置。我添加了位置为^2.3.5和地理定位器为^5.0.1的插件以获取当前位置。 一切正常,但当我的设备GPS关闭(禁用)时,它会显示一个我在图中显示的对话框。请检查它。我需要按“确定”按钮返回,以便获得当前位置并执行下一个代码行。如果你帮助我,我会感谢你的 这里有一些代码Flutter 如何获得谷歌位置服务对话框按钮的回拨点击';什么在飘动?,flutter,geolocation,flutter-dependencies,Flutter,Geolocation,Flutter Dependencies,我需要在我的Flatter应用程序中获取设备的当前位置。我添加了位置为^2.3.5和地理定位器为^5.0.1的插件以获取当前位置。 一切正常,但当我的设备GPS关闭(禁用)时,它会显示一个我在图中显示的对话框。请检查它。我需要按“确定”按钮返回,以便获得当前位置并执行下一个代码行。如果你帮助我,我会感谢你的 这里有一些代码 getCurrentLocation() async{ try { await location.getLocation().then((locationData){
getCurrentLocation() async{
try {
await location.getLocation().then((locationData){
if(locationData!=null){
moveHomeWithLatLon(context,false,locationData.latitude.toString(),locationData.longitude.toString());
}else{
dialogInternetCheck(context, alert, "Please check location services on device");
}
});
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
dialogInternetCheck(context, alert, "Location services "+error);
}
}
}您应该在请求定位服务后检查服务状态结果。如果为真,则表示用户已提供访问权限。我提供了下面的例子
bool serviceStatusResult = await location.requestService();
print("Service status activated after request: $serviceStatusResult");
if (serviceStatusResult) {
await _getCurrentLocation();
}
Future<bool> _getCurrentLocation() async {
try {
Location location = Location();
LocationData userLocation = await location.getLocation();
} on PlatformException catch (e) {
Log.info("Location fetch failed : ${e.toString()}");
}
return Future.value(true);
}
boolservicestatusresult=wait location.requestService();
打印(“请求后激活的服务状态:$serviceStatusResult”);
如果(serviceStatusResult){
等待_getCurrentLocation();
}
Future\u getCurrentLocation()异步{
试一试{
位置=位置();
LocationData userLocation=等待位置。getLocation();
}平台上异常捕获(e){
Log.info(“位置提取失败:${e.toString()}”);
}
返回未来值(true);
}