Flutter & Geocoder & Geolocator:如何获取英文国家名称?
Flutter & Geocoder & Geolocator : How do I get the country name in English?
我一直在尝试获取 phone 位置。出于某种原因,地理编码器使用韩语获取国家/地区名称。 phone 反正主要语言是英文。但是为什么我得到的是韩语呢?
_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
});
}
更改您的 phone 语言。或者使用“first.countryCode”。
我一直在尝试获取 phone 位置。出于某种原因,地理编码器使用韩语获取国家/地区名称。 phone 反正主要语言是英文。但是为什么我得到的是韩语呢?
_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
});
}
更改您的 phone 语言。或者使用“first.countryCode”。