简体   繁体   中英

Getting english name of country instead of name in device language?

How can I get english name of country instead of name in my choosen device language?

public static String getCountryName(Context context, double latitude, double longitude) {
    Geocoder geocoder = new Geocoder(context, Locale.getDefault());
    List<Address> addresses = null;
    try {
        addresses = geocoder.getFromLocation(latitude, longitude, 1);
        Address result;

        if (addresses != null && !addresses.isEmpty()) {
            return addresses.get(0).getCountryName();
        }
        return null;
    } catch (IOException ignored) {
        //do something
        return null;
    }
}

Can you help me?

Why using the default Locale? This should work:

Geocoder geocoder = new Geocoder(context, Locale.ENGLISH);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM