Wednesday, 27 March 2019

Get Full Address From Latitude and Longitude Android Google Map

Get Full Address From Latitude and Longitude Android Google Map

String zipCode = getZipCode(MapsActivity.this,arg0.latitude,arg0.longitude);
Toast.makeText(MapsActivity.this,""+zipCode,Toast.LENGTH_LONG).show();





public String getZipCode(Context c, double lat, double lng){
    String fullAdd = null;
    String locality = null;
    String zip = null;
    String country = null;
    try {
        Geocoder geocoder = new Geocoder(c,Locale.getDefault());
        List<Address> addresses = geocoder.getFromLocation(lat,lng,1);
        if (addresses.size()>0){
            Address address = addresses.get(0);
            fullAdd = address.getAddressLine(0);  // full Address  
            locality = address.getLocality();
            zip = address.getPostalCode();
            country = address.getCountryName();
        }

    }catch (IOException ex){
        ex.printStackTrace();
    }
    return zip;
}

3 comments: