Это мой код (в основном взят из Flutter Projects Симоны Алессандрии, а некоторые изменения взяты из Интернета, пытаясь решить эту проблему)
Код: Выделить всё
Future _getCurrentLocation() async {
bool isGeolocationAvailable = await Geolocator.isLocationServiceEnabled();
if (isGeolocationAvailable) {
try {
Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.best, timeLimit: Duration(seconds: 10)).then((pos) {
setPosition(pos);
});
} catch (error) {
print(error.toString());
Geolocator.getLastKnownPosition().then((pos) {
setPosition(pos);
});
}
}
return null;
}
Вот мой доктор Flutter на всякий случай:
Код: Выделить всё
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.5.1, on Ubuntu 20.04.3 LTS 5.11.0-38-generic, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.1)
[✓] Android Studio (version 4.1)
[✓] VS Code
[✓] Connected device (1 available)
• No issues found!
Код: Выделить всё
environment:
sdk: ">=2.14.2
Подробнее здесь: [url]https://stackoverflow.com/questions/70018164/flutter-geolocator-getcurrentposition-never-returns[/url]
Мобильная версия