Search code examples
androidzipcode

Fetch zipcode from latlng


Which webservice should i use to get the zipcode from latitude and longitude? I am using Geonames API but it doesnot meet the requirement. I want to use anyother webservices which provides the zipcode/postalcode.

        Geocoder geocoder;
        List<Address> addresses;
        geocoder = new Geocoder(this, Locale.getDefault());
        addresses = geocoder.getFromLocation(_mylat, _mylong, 1);
        String address = addresses.get(0).getAddressLine(0);
        String city = addresses.get(0).getAddressLine(1);
        String country = addresses.get(0).getAddressLine(2);
                        String zipcode = addresses.get(0).getPostalCode();

Even I tried this code but i didnt get the result. I got the Exception as IndexOutOfBoundException.


Solution

  • Geocoder geocoder;
                List<Address> addresses;
                geocoder = new Geocoder(this, Locale.getDefault());
                addresses = geocoder.getFromLocation(_mylat, _mylong, 1);
                String address = addresses.get(0).getAddressLine(0);
                String city = addresses.get(0).getAddressLine(1);
                String country = addresses.get(0).getAddressLine(2);
                                String zipcode = addresses.get(0).getPostalCode();