【问题标题】:Geocoder returns location in another language even when set to english即使设置为英语,地理编码器也会以另一种语言返回位置
【发布时间】:2020-02-01 14:16:16
【问题描述】:

我正在使用以下代码,并且我已经尝试了有关堆栈溢出的大部分答案,但它仍然为某些用户返回不同语言的位置。

会发生什么:
对于某些用户,即使我将默认语言设置为英语,它也会返回尼泊尔语的位置。我确实尝试过将手机的语言更改为尼泊尔语,但它以英语返回。

我的代码:
关于创建片段

Locale.setDefault(Locale.ENGLISH); 
LocationRetreive(locationLatitude, locationLongitude);

方法

    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();
    }
}

可能是什么原因?

【问题讨论】:

标签: android google-geocoder


【解决方案1】:

试试

Locale.setDefault(new Locale("en", "GB"));  
Locale new_locale = Locale.getDefault();

改为。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-11
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    • 1970-01-01
    • 2023-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多