public static void logAddress(String logTag, Address address) {

    int maxAddressLineIndex = address.getMaxAddressLineIndex();
    for (int i = 0; i <= maxAddressLineIndex; i++) {
      String addressLine = address.getAddressLine(i);
      Log.d(logTag, i + ":  " + addressLine);
    }

    double latitude = 0.0d;
    double longitude = 0.0d;

    boolean hasLatitude = address.hasLatitude();
    if (hasLatitude) {
      latitude = address.getLatitude();
    }
    boolean hasLongitude = address.hasLongitude();
    if (hasLongitude) {
      longitude = address.getLongitude();
    }

    String adminArea = address.getAdminArea();
    String featureName = address.getFeatureName();
    String locality = address.getLocality();
    String postalCode = address.getPostalCode();
    String premises = address.getPremises();
    String subAdminArea = address.getSubAdminArea();
    String subLocality = address.getSubLocality();
    String subThoroughfare = address.getSubThoroughfare();
    String thoroughfare = address.getThoroughfare();
    String phone = address.getPhone();
    String url = address.getUrl();

    // logValue(logTag, "latitude", hasLatitude, latitude);
    // logValue(logTag, "longitude", hasLongitude, longitude);
    //        logValue(logTag,"adminArea", adminArea);
    //        logValue(logTag,"featureName", featureName);
    //        logValue(logTag,"locality", locality);
    //        logValue(logTag,"postalCode", postalCode);
    //        logValue(logTag,"premises", premises);
    //        logValue(logTag,"subThoroughfare", subThoroughfare);
    //        logValue(logTag,"subAdminArea",subAdminArea);
    //        logValue(logTag,"subLocality", subLocality);
    //        logValue(logTag,"thoroughfare", thoroughfare);
    //        logValue(logTag,"phone", phone);
    //        logValue(logTag,"url", url);
  }
    /**
     * Get a Geocoder instance, get the latitude and longitude look up the address, and return it
     *
     * @params params One or more Location objects
     * @return A string containing the address of the current location, or an empty string if no
     *     address can be found, or an error message
     */
    @Override
    protected String doInBackground(Location... params) {

      Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
      // Get the current location from the input parameter list
      Location loc = params[0];
      // Create a list to contain the result address
      List<Address> addresses = null;
      try {
        /*
         * Return 1 address.
         */
        addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1);
      } catch (IOException e1) {
        Log.e("LocationSampleActivity", "IO Exception in getFromLocation()");
        e1.printStackTrace();
        return ("IO Exception trying to get address");
      } catch (IllegalArgumentException e2) {
        // Error message to post in the log
        String errorString =
            "Illegal arguments "
                + Double.toString(loc.getLatitude())
                + " , "
                + Double.toString(loc.getLongitude())
                + " passed to address service";
        Log.e("LocationSampleActivity", errorString);
        e2.printStackTrace();
        return errorString;
      }
      // If the reverse geocode returned an address
      if (addresses != null && addresses.size() > 0) {
        // Get the first address
        Address address = addresses.get(0);
        /*
         * Format the first line of address (if available), city, and
         * country name.
         */

        String addressMessage = address.getAddressLine(0) + " " + address.getAddressLine(1);
        String addressText =
            String.format(
                "%s, %s, %s, %s",
                // If there's a street address, add it
                address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                // Locality is usually a city
                address.getLocality(),
                address.getPremises(),
                // The country of the address
                address.getCountryName());

        // streetAddress = address.getAddressLine(1);
        // Return the text

        streetadd =
            address.getAddressLine(0)
                + ","
                + address.getAddressLine(1)
                + ","
                + address.getCountryName();

        Log.e(
            "TAG",
            address.getAddressLine(0)
                + ""
                + address.getCountryCode()
                + " "
                + address.getCountryName());
        countryId = address.getCountryCode();
        country = address.getCountryName();
        adlevel1 = address.getAdminArea();
        adlevel2 = address.getSubAdminArea();
        // streetadd = address.getAddressLine(0)
        // + address.getAddressLine(1);
        locality = address.getLocality();
        postalcode = address.getPostalCode();

        Log.e("check country code", "" + address.getCountryCode());
        Log.e("Locale", "" + address.getLocale());
        Log.e("Maxaddlineindex", "" + address.getMaxAddressLineIndex());
        Log.e("subadminarea", "" + address.getSubAdminArea());
        Log.e("addres line", "" + address.getAddressLine(0));
        Log.e("addres line 1", "" + address.getAddressLine(1));
        Log.e("adminarea", "" + address.getAdminArea());
        Log.e("featurename", "" + address.getFeatureName());
        Log.e("adminarea", "" + address.getAdminArea());
        Log.e("Locality", "" + address.getLocality());
        Log.e("premises", "" + address.getPremises());
        Log.e("postalcode", "" + address.getPostalCode());
        Log.e("sublocality", "" + address.getSubLocality());
        Log.e("extras", "" + address.getExtras());

        Log.e("back country", "" + country);

        Log.e("streetAddress", "" + streetadd);
        return addressMessage;
      } else {
        return "No address found";
      }
    }