我正在尝试使用 Geolocator 包获取 Flutter 中的当前地理位置,但它不起作用。这是我的功能代码:
local() async {
final Geolocator geolocator = Geolocator()..forceAndroidLocationManager = true;
var position = await geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.low);
print(position);
}
它正在打印NULL。
注意:我已经在 AndroidManifest 中设置了适当的权限以及 geolocator API 密钥。
地理定位器包版本:5.3.0
Flutter Doctor:(我目前无法使用最新版本的flutter)
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.17.5, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.48.2)
[✓] Connected device (1 available)
• No issues found!