How to get complete address from latitude and longitude?
Geocoder geocoder;List<Address> addresses;geocoder = new Geocoder(this, Locale.getDefault());addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()String city = addresses.get(0).getLocality();String state = addresses.get(0).getAdminArea();String country = addresses.get(0).getCountryName();String postalCode = addresses.get(0).getPostalCode();String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL
For more info of available details, Look at Android-Location-Address
Try this My friend
private String getCompleteAddressString(double LATITUDE, double LONGITUDE) { String strAdd = ""; Geocoder geocoder = new Geocoder(this, Locale.getDefault()); try { List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1); if (addresses != null) { Address returnedAddress = addresses.get(0); StringBuilder strReturnedAddress = new StringBuilder(""); for (int i = 0; i <= returnedAddress.getMaxAddressLineIndex(); i++) { strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("\n"); } strAdd = strReturnedAddress.toString(); Log.w("My Current loction address", strReturnedAddress.toString()); } else { Log.w("My Current loction address", "No Address returned!"); } } catch (Exception e) { e.printStackTrace(); Log.w("My Current loction address", "Canont get Address!"); } return strAdd; }
City & Country are not Always getting in address Line 1 & Line 2...
Example is here
So,
Geocoder geocoder = new Geocoder(context, Locale.getDefault());List<Address> addresses = geocoder.getFromLocation(latitude,longitude, 1);String address = addresses.get(0).getAddressLine(0);String city = addresses.get(0).getLocality();String state = addresses.get(0).getAdminArea();String zip = addresses.get(0).getPostalCode();String country = addresses.get(0).getCountryName();