android - Flutter 位置中的 PlatformException(错误,无法获取位置。,null):^1.4.1
问题描述
我正进入(状态
PlatformException(错误,获取位置失败。,null)
使用颤振从设备获取位置时,位置:^1.4.1。任何人都可以帮忙吗?
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
_getLocation();
return Container();
}
Future<Map<String, double>> _getLocation() async {
var location = new Location();
try {
var _permission = await location.hasPermission();
print(_permission);
var currentlocation = await location.getLocation();
print(currentlocation["latitude"]);
return currentlocation;
} on Exception catch (e) {
print(e);
}
}
}
堆栈跟踪 -
I/flutter (28694): true
I/flutter (28694): PlatformException(ERROR, Failed to get location., null)
解决方案
所以你把那个包通过flutter pub get
...你也重建了整个项目吗?可能是因为它没有构建插件的本机端。
Stop and Re-Run
可能有帮助。
推荐阅读
- javascript - 无法从 JSON 文件中获取获取的数据到新函数中
- sql - 通过触发器更新另一个表,其中新值是 SELECT 查询的结果
- php - 为什么 PHP 在不更改条件的情况下交换两行后反向打印此函数
- ios - 当 BLE 在 Swift 中以编程方式连接时,蓝牙设备设置中缺少信息按钮
- python - 在 Jupyter Notebook 上安装 seaborn 和 sklearn 时出错
- c++ - 为什么我不能编译这个简单的线程测试?
- php - 如何在 Laravel - Blade 的 textarea 值属性中使用变量?
- python - 您可以在 tkinter 中设置更新方法吗?
- c++ - Xcode 上的 assimp 导入失败
- c# - 什么定义了“隔离”测试?