How to get the full ZIP using Geocodelocation on Android?

Asked

Viewed 685 times

1

I’m using the GPS to return the user’s address. Everything works very well, but the returned zip code is in the American standard, with 5 digits. Does anyone know any library or any way to get the Brazilian 8-digit standard ?

public static void getAddressFromLocation(final double latitude, final double longitude, final Context context, final Handler   handler)    
{
    Thread thread = new Thread() {
        @Override
        public void run() {
            Geocoder geocoder = new Geocoder(context, Locale.getDefault());
            String result = null;

            // String tudo[] = new String[0];
            try {
                List<Address> addressList = geocoder.getFromLocation(
                        latitude, longitude, 1);
                if (addressList != null && addressList.size() > 0) {
                    Address address = addressList.get(0);
                    StringBuilder sb = new StringBuilder();
                    for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
                        sb.append(address.getAddressLine(i)).append("\n");
                       // tudo[i] = address.getAddressLine(i).concat("\n");
                    }
                      sb.append(address.getAdminArea()).append("\n");
                      sb.append(address.getLocality()).append("\n");
                      sb.append(address.getPostalCode()).append("\n");

                    result = sb.toString();

                }
            }
        }
    }
}
  • 1

    Could you show us how your code is? I can’t tell if you’re using a specific API, could you inform? Grateful

  • I don’t know much, but he tried to trade Locale.getDefault()?

  • Is your device in English? Probably the line Locale.getDefault() is returning another region.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.