Skip to content

Instantly share code, notes, and snippets.

@MohammadSamandari
Created March 31, 2019 21:36
Show Gist options
  • Save MohammadSamandari/1a4495efcf20590e1d616658bb6a224e to your computer and use it in GitHub Desktop.
Save MohammadSamandari/1a4495efcf20590e1d616658bb6a224e to your computer and use it in GitHub Desktop.
Learning: Getting Address From LatLon
// Reverse GeoCoding
// Getting The address from a Location coordinates.
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
// Locale: format for the address. getDefault() use the Locale of the user.
try {
List<Address> listAddresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
// We have to say how many result we want, so that integer is for that.
// we do a check to see if we got something back or not.
if (listAddresses != null && listAddresses.size() > 0) {
String countryName = listAddresses.get(0).getCountryName();
String cityName = listAddresses.get(0).getLocality();
String feature = listAddresses.get(0).getFeatureName();
String addressLine0 = listAddresses.get(0).getAddressLine(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment