Created
May 29, 2018 16:06
-
-
Save shaon2016/6b0085f6420eb1d965b3f660c9be6b53 to your computer and use it in GitHub Desktop.
Get the address using lat lng
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
private void gettingAddressUsingLatLng(double latitude, double longitude) { | |
Geocoder geocoder = new Geocoder(this, Locale.getDefault()); | |
List<Address> addresses = null; | |
try { | |
addresses = geocoder.getFromLocation( | |
latitude, | |
longitude, | |
1); | |
}catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// Handle case where no address was found. | |
if (addresses != null || addresses.size() > 0) { | |
Address address = addresses.get(0); | |
StringBuilder sb = new StringBuilder(); | |
// Fetch the address lines using getAddressLine, | |
// join them, and send them to the thread. | |
for(int i = 0; i <= address.getMaxAddressLineIndex(); i++) { | |
sb.append(address.getAddressLine(i)).append("\n"); | |
sb.append(address.getLocality()).append("\n"); | |
sb.append(address.getCountryName()); | |
} | |
sessionManager.setAddress(sb.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment