try {
addresses = gcd.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses.size() > 0) {
String toastMsg = String.format("Place: %s", addresses.get(0).getLocale() + " - " + addresses.get(0).getCountryName() + " - " + addresses.get(0).getCountryCode());
Toast.makeText(this, toastMsg, Toast.LENGTH_LONG).show();
}
答案 0 :(得分:0)
我找到了解决方案,谢谢所有开发者android
Geocoder gcd = new Geocoder(getActivity(), Locale.getDefault());
List<Address> addresses = null;
try {
addresses = gcd.getFromLocation(place.getLatLng().latitude, place.getLatLng().longitude, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses.size() > 0) {
/*
getCity --> addresses.get(0).getLocality()
getCountry --> addresses.get(0).getCountryName()
getCodeCountry --> addresses.get(0).getCountryCode() (MA)
*/
city = String.format("%s",addresses.get(0).getLocality());
country= String.format("%s",addresses.get(0).getCountryName());
tvCountry.setText(country);
tvCity.setText(city);
}