Мне нужно получить название города по долготе и широте. Я не нашел ни одного пакета для этого, поэтому я использую пакет местоположения, чтобы получить долгую и широту, и использовал геокодер для получения названия города.
Но у меня сохраняется эта ошибка и нет результата:
[ОШИБКА: flutter / lib / ui / ui_dart_state.cc (177)] Необработанное исключение: PlatformException (failed, Failed, null, null)
и следующий за ним на консоли: ‹асинхронная приостановка›
Вот мой код:
class _ProfileScreenState extends State<ExploreScreen> {
dynamic currentLocation;
double userLongitude;
double userLatitude;
Coordinates coordinates;
var addresses;
var first;
@override
initState() {
super.initState();
_getCurrentLongAndLat();
_getCurrentPosition(userLatitude, userLatitude);
}
Future _getCurrentLongAndLat() async {
currentLocation = LocationData;
var error;
var location = new Location();
try {
currentLocation = await location.getLocation();
userLatitude = currentLocation.latitude;
userLongitude = currentLocation.longitude;
print('$userLatitude $userLatitude');
} on PlatformException catch (e) {
if (e.code == 'PERMISSION_DENIED') {
error = 'Permission denied';
}
currentLocation = null;
}
}
Future _getCurrentPosition(double long, double lat) async {
coordinates = new Coordinates(userLatitude, userLongitude);
addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
print(addresses.first);
}
}