Created
March 31, 2019 21:36
-
-
Save MohammadSamandari/1a4495efcf20590e1d616658bb6a224e to your computer and use it in GitHub Desktop.
Learning: Getting Address From LatLon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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