1

I have gone through the different question here on Stackoverflow but none of them helped me out yet. I am using google API in my app and needs to retrieve the zipcode. Currently I am getting all the other parameters but zipcode.

Any suggestion/guidance or help would be highly appreciated. Thanks.

enter image description here

Geocoder geocoder;

    List<Address> addresses;
    geocoder = new Geocoder(activity, Locale.getDefault());

    try {
        addresses = geocoder.getFromLocation(Double.parseDouble(params[0]), Double.parseDouble(params[1]), 1);

        //get current Street name
        String address = addresses.get(0).getAddressLine(0);

        //get current province/City
        String province = addresses.get(0).getAdminArea();

        //get country
        String country = addresses.get(0).getCountryName();

        //get postal code
        String postalCode = addresses.get(0).getPostalCode();
        //get place Name
        String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL

        return "Street: " + address + "\n" + "City/Province: " + province + "\nCountry: " + country
                + "\nPostal CODE: " + postalCode + "\n" + "Place Name: " + knownName;

    } catch (IOException ex) {
        ex.printStackTrace();
        return "IOE EXCEPTION";

    } 
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • It seems that you'll be needing to use web service for this one as indicated in this [thread](http://stackoverflow.com/questions/18568446/how-to-get-postal-code-using-user-current-location-in-android). – ReyAnthonyRenacia May 06 '16 at 14:06
  • I also have used web service, that also don't show postal_code in Pakistan ....but working fine other than Pakistan.... – Farrukh Chishti May 09 '16 at 06:09
  • Have you tried SmartyStreets? Demo international addresses here: https://smartystreets.com/products/single-address?country=&address1=&address2=&locality=&administrative_area=&postal_code=&address-type=international-street-components. – Joseph Hansen May 05 '17 at 21:25

0 Answers0