Search This Blog

Support my cause by downloading

Wednesday, 24 April 2013

Android Reverse Geo Coding : Getting Human Readable address from latitude and longitude in android

We can show any address on map using latitude and longitude. But showing number rather than any useful information make no sense for any user. Reverse Geo Coding is process to convert latitude and longitude into one readable address in the form of String

     public String getAddress(Activity acLocal) {
 String address="";
       Geocoder geocoder;
        List<Address> addresses = null;
        geocoder = new Geocoder(_acLocal, Locale.getDefault());
        try {
            addresses = geocoder.getFromLocation(lat, longi, 1);

            String address = addresses.get(0).getAddressLine(0);
            String city = addresses.get(0).getAddressLine(1);
            String country = addresses.get(0).getCountryName();
            address = Html.fromHtml(
                    address + "<br>" + city + "<br>" + country).toString();
        } catch (Exception e) {
            e.printStackTrace();
            address = Html.fromHtml("<br>&nbsp;Unable to get any address.")
                    .toString();
        }
       return address;
} 

It will give you available address for respective latitude and longitude. Throws an exception if not able to convert into address
Android News and source code