【问题标题】:Geocoder locale language always return english地理编码器语言环境总是返回英文
【发布时间】:2019-02-11 07:12:13
【问题描述】:

我尝试根据当前位置使用特定语言获取城市,我之前像下面那样做,一切都很好,但在我的新项目中它不起作用!

 Geocoder geo = new Geocoder(getApplicationContext(), new Locale("ja"));
                        List<Address> addresses = null;
                        try {
                            addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);

                            if (addresses.size() > 0) {

                                Log.d("CITY",addresses.get(0).getLocality());
                                city.setText(addresses.get(0).getLocality());

                            } else {
                                // do your stuff
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }

无论设置哪种语言,城市名称总是以英文返回!

【问题讨论】:

    标签: android geolocation locale android-location


    【解决方案1】:

    经过一些研究,我明白必须设置geo.getFromLocation maxResults &gt; 1,因为列表中总是返回第一个地址,返回英文,但下一个项目将是您的特定语言,所以只需要更改

    addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 1);

    到

    addresses = geo.getFromLocation(location.getLatitude(), location.getLongitude(), 2); 和 getLocality 这样addresses.get(1).getLocality()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多