android - 在颤动中打开位置后如何更新我的位置
问题描述
我是 Flutter 的新手,我想在这个例子中实现一些目标,我想在用户打开位置后更新用户位置,假设用户在我们给用户一个弹出窗口说这个应用程序之后没有先打开他的位置需要位置然后它应该更新数据但在下面的示例中它不起作用,请帮助我。
PS:
解决方案
只需像示例中一样订阅“onLocationChanged”流。
_location.onLocationChanged().listen((Map<String,double> result) {
var latitude = result["latitude"]; //This is called always when the location updates
var longitude = result["longitude"];
});
要在用户未启用位置时显示弹出窗口,请使用以下命令:
try {
currentLocation = await location.getLocation;
} on PlatformException {
await showDialog<dynamic>(
context: context,
builder: (context) {
return AlertDialog(
title: Text("No Location"),
content: Text(
"Please allow this App to use Location or turn on your GPS."),
actions: <Widget>[
FlatButton(
child: Text(
"Ok"
),
onPressed: () {
Navigator.of(context).pop();
},
)
],
);
});
}
推荐阅读
- sql - SQL:使用前一行的值填充当前行
- mysql - 是否可以在时间戳上对 Mysql 表进行索引
- python - 输入两个单独的列表并输出一个字典列表
- android - 如何从可移动 sd 卡路径中获取所有文件路径和名称?
- c++ - 如何检查用户输入是否超过一个字母并在 C++ 中正确显示
- database - DynamoDB DAX 是否可以水平扩展?
- eclipse-plugin - Eclipse Oxygen 不与 VSS 连接
- ios - 设备锁定时是否可以处理通知操作?
- marklogic - MarkLogic 内容处理框架 (CPF) 管道必须是线性的还是非循环的?
- oracle - 如何删除oracle数据库速成版