我一直在尝试获取电话位置。由于某种原因,地理编码器以韩文获得了国家/地区名称。电话的主要语言还是英语。但是为什么我会用韩文呢?
_getCurrentLocation() async {
Position position =
await getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
final coordinates =
new Coordinates(position.latitude, position.longitude);
final addresses =
await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
print(first.adminArea);
print(first.countryName);
}
安慰I/flutter ( 7221): We have Latitude: 37.4219983, Longitude: -122.084
I/flutter ( 7221): Latitude : 37.4219983 & Longtitude : -122.084
I/flutter ( 7221): California
I/flutter ( 7221): 미국
请看看并在这方面帮助我。谢谢。 最佳答案
试试这个
String _address = ""; // create this variable
void _getPlace() async {
List<Placemark> newPlace = await
_geolocator.placemarkFromCoordinates(_position.latitude, _position.longitude);
// this is all you need
Placemark placeMark = newPlace[0];
String name = placeMark.name;
String subLocality = placeMark.subLocality;
String locality = placeMark.locality;
String administrativeArea = placeMark.administrativeArea;
String postalCode = placeMark.postalCode;
String country = placeMark.country;
String address = "${name}, ${subLocality}, ${locality}, ${administrativeArea}
${postalCode}, ${country}";
print(address);
setState(() {
_address = address; // update _address
});
}
关于flutter - Flutter&Geocoder&Geolocator:如何以英语获取国家名称?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/64056975/