Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Getting address and city from lot/long in Java

    • 0
    • 4
    • 1
    • 4
    • 0
    • 0
    • 0
    • 0
    • 1.05k
    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 Address and city from Latitude/Longitude:

    public static String[] getCityAndAddress(Double latitude, Double longitude)
        logger.debug("latitude :  "+latitude+" longitude: "+longitude);
        String[] addressArray = new String[2];
            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();
            //This will print geographical information        
            logger.debug("results :  "+results);
            List<GeocoderAddressComponent> geList= results.get(0).getAddressComponents();
            for(int i =0; i < geList.size(); i++)
                    addressArray[0] = geList.get(i).getLongName();
            addressArray[1] = results.get(0).getFormattedAddress();
            logger.debug("addressArray :  " + addressArray);
        }catch (Exception e) {
        return addressArray;

    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: