Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Getting ZipCode from lat/long in android

    • 0
    • 3
    • 1
    • 4
    • 0
    • 0
    • 0
    • 0
    • 3.73k
    Comment on it

    This blog will help you in getting geographical information of any location by using latitude/longitude.

    By using Java API Geocoder, it is easy to get geographical information of any location. The response will be in JSON or XML format.

    Write the following example to get Zip code from Latitude/Longitude:

    private String getZipCode(Double latitude, Double longitude)
        String zipcode = null;
            LatLng latLng = new LatLng();
            final Geocoder geocoder = new Geocoder();
            GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setLocation(latLng).getGeocoderRequest();
            GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
            List<GeocoderResult> results = geocoderResponse.getResults();
            logger.debug("results :  "+results); //This will print geographical information
            List<GeocoderAddressComponent> geList= results.get(0).getAddressComponents();
                zipcode = geList.get(geList.size()-1).getLongName();
            else if(geList.get(0).getTypes().get(0).trim().equalsIgnoreCase("postal&#95;code"))
                zipcode = geList.get(0).getLongName();
            logger.debug("zipcode :  " + zipcode);
        }catch (Exception e) {
        return zipcode;

    Write the following Maven configuration in pom.xml file in your project:


    Hope this will help you :)

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: