问题
I am using the following code and I have tried most of answers on stack-overflow but still it returns the location in different languages for some users.
What Happens:
For some users even if I set default language to English, it returns the location in Nepali. I did try myself by changing my phones language to Nepali but its returning in English.
My Code:
on Create Fragment
Locale.setDefault(Locale.ENGLISH);
LocationRetreive(locationLatitude, locationLongitude);
Method
private void LocationRetreive(Double locationLatitude, Double locationLongitude) {
try {
Geocoder geocoder = new Geocoder(getContext(), Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(locationLatitude, locationLongitude, 1);
if (addresses != null && addresses.size() > 0) {
string_city = addresses.get(0).getLocality();
string_state = addresses.get(0).getAdminArea();
string_country = addresses.get(0).getCountryName();
string_location = addresses.get(0).getAddressLine(0);
if (string_country == null) {
if (string_state != null) {
string_country = string_state;
} else if (string_city != null) {
string_country = string_city;
} else {
string_country = "null";
}
}
if (string_city == null) {
if (string_state != null) {
string_city = string_state;
} else {
string_city = string_country;
}
}
if (string_state == null) {
if (string_city != null) {
string_state = string_city;
} else {
string_state = string_country;
}
}
if (string_location == null) {
string_location = "Null";
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
What can be the reason?
Please help.
来源:https://stackoverflow.com/questions/60017702/geocoder-returns-location-in-another-language-even-when-set-to-english