为什么我的应用程序在语言更改后无法获取地址?

时间:2012-12-21 08:19:03

标签: android google-maps

我从位置获取地址:

GeoPoint p;
        Geocoder geocoder = new Geocoder(this, Locale.getDefault());
        Location location = new Location("A");
        location.setLatitude(34.7461307);
        location.setLongitude(135.5738767);
        p = new GeoPoint((int) (location.getLatitude() * 1E6),
                (int) (location.getLongitude() * 1E6));
        List<Address> add = null;
        try {
            add = geocoder.getFromLocation(p.getLatitudeE6() / 1E6,
                    p.getLongitudeE6() / 1E6, 1);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
        }
        String addressjian = null;
        if (add != null && add.size() > 0) {
            // Get address
            String post = "";

            for (int i = 0; i <= add.get(0).getMaxAddressLineIndex(); i++) {
                String country = add.get(0).getCountryName();
                post = add.get(0).getPostalCode();
                if (!add.get(0).getAddressLine(i).equals(country)) {
                    if (addressjian != null && !addressjian.equals("")) {
                        addressjian = addressjian + ", ";
                    }
                    addressjian += add.get(0).getAddressLine(i);
                }

            }

        }

如果我将语言设置为英语,结果是:

[Address[addressLines=[0:"1丁目-21 Yagumo Higashimachi",1:"Moriguchi, Osaka Prefecture 570-8588",2:"Japan"],feature=570-8588,admin=null,sub-admin=null,locality=null,thoroughfare=null,postalCode=570-8588,countryCode=JP,countryName=Japan,hasLatitude=true,latitude=34.7456387,hasLongitude=true,longitude=135.5744525,phone=null,url=null,extras=null]]

但如果我将语言设置为日语,结果是:

[Address[addressLines=[0:"〒570-8588",1:"日本"],feature=570-8588,admin=null,sub-admin=null,locality=null,thoroughfare=null,postalCode=570-8588,countryCode=JP,countryName=日本,hasLatitude=true,latitude=34.7456387,hasLongitude=true,longitude=135.5744525,phone=null,url=null,extras=null]]

为什么它没有得到街道的名字?为什么它取决于设备的语言?

0 个答案:

没有答案