Geocoder returns location in another language even when set to english

匆匆过客 提交于 2020-02-08 10:03:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!