代码之家  ›  专栏  ›  技术社区  ›  Erfan

地理编码语言总是返回英语

  •  0
  • Erfan  · 技术社区  · 6 年前

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

    不管用哪种语言设置,城市名称总是用英语返回!

    1 回复  |  直到 6 年前
        1
  •  2
  •   Erfan    6 年前

    经过一番研究,我明白我必须 geo.getFromLocation maxResults > 1

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

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