Skip to content

Instantly share code, notes, and snippets.

@shaon2016
Created May 29, 2018 16:06
Show Gist options
  • Save shaon2016/6b0085f6420eb1d965b3f660c9be6b53 to your computer and use it in GitHub Desktop.
Save shaon2016/6b0085f6420eb1d965b3f660c9be6b53 to your computer and use it in GitHub Desktop.
Get the address using lat lng
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