Flutter 地理定位器无法获取准确的当前位置,并且它始终返回相同的纬度和经度值
这是我的代码
void getlocation() async {
LocationPermission per = await Geolocator.checkPermission();
if (per == LocationPermission.denied ||
per == LocationPermission.deniedForever) {
print("permission denied");
LocationPermission per1 = await Geolocator.requestPermission();
} else {
Position currentLoc = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);
setState(() {
long = currentLoc.longitude.toString();
lat = currentLoc.latitude.toString();
});
}
}
这是我将长和纬度值返回到屏幕时的输出,并且该值将始终相同。即使我手动将位置设置到其他地方,稍后它也会再次回到这个位置 输出
Here's my code
void getlocation() async {
LocationPermission per = await Geolocator.checkPermission();
if (per == LocationPermission.denied ||
per == LocationPermission.deniedForever) {
print("permission denied");
LocationPermission per1 = await Geolocator.requestPermission();
} else {
Position currentLoc = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.best);
setState(() {
long = currentLoc.longitude.toString();
lat = currentLoc.latitude.toString();
});
}
}
Here's the output when i return long and lat value to my screen and the value will always be the same. even i manually set the position to other places, it will go back to this position again later on
output
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Geolocator 包返回模拟器上的默认位置。如果您使用的是 Android 模拟器,您可以在此处手动更改模拟器设置的位置,之后,您必须在模拟器上打开谷歌地图并点击“获取位置”按钮,以便模拟器注册这个新位置。
此后,您可以返回并运行您的应用程序。应该会显示您设置的这个新位置。
The Geolocator package returns the default location on your emulator. If you are using an android emulator, you can manually change the location from the emulator settings here, after which you have to open google maps on the emulator and tap on the get location button so the emulator registers this new location.
Thereafter, you can go back and run your app. should have this new location you set showing up.