How to Get Address from Latitude/Longitude in Android
Takahiro Iwasa
1 min read
Android GIS Java
It has been more than 3 years since this post was published.
Addresses can be obtained from latitude/longitude using android.location.Geocoder
in Android. Happy Coding!
/**
* Get address from latitude/longitude.
* @param context
* @param latitude
* @param longitude
* @return Address
*/
public static String getAddress(
Context context, double latitude, double longitude) {
Geocoder geocoder = new Geocoder(context, Locale.getDefault());
List<Address> addresses;
StringBuilder result = new StringBuilder();
try {
addresses = geocoder.getFromLocation(latitude, longitude, 1);
}
catch (IOException e) {
return "";
}
for (Address address : addresses) {
int idx = address.getMaxAddressLineIndex();
// Omit the first record including a country name.
for (int i = 1; i <= idx; i++) {
result.append(address.getAddressLine(i));
}
}
return result.toString();
}