当前位置动摇 [英] Current location with flutter
本文介绍了当前位置动摇的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在检索当前位置时遇到问题.
I am having issue with retrieve the current location.
第1步:当我按下按钮时,它将打开用于启用位置服务的默认弹出窗口,因为我检查它没有启用位置.
Step 1: when i press a button it will open the default popup for enable the location service,as i inspected it doesn't enable the location.
第2步:如果我手动启用该位置,我会得到当前位置,如果我执行了第一步,它将不起作用
Step 2: If i enable the location manually i am getting the current location,if i do the first step it doesn't work
final Location location = Location();
LocationData _location;
String _error;
Future<void> _getLocation() async {
setState(() {
_error = null;
});
try {
final LocationData _locationResult = await location.getLocation();
setState(() {
_location = _locationResult;
});
} on PlatformException catch (err) {
setState(() {
_error = err.code;
});
}
}
推荐答案
这是如何使用位置信息包获取位置信息的示例
This is a sample of how to get the location using the location package
Future _getLocation() async {
Location location = new Location();
LocationData _pos = await location.getLocation();
SharedPrefrence().setLatitude(_pos.latitude);
SharedPrefrence().setLongitude(_pos.longitude);
}
在此处
这篇关于当前位置动摇的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文