I have the below code to convert lat, long to human readable address. Now i am some time getting full details of address including address, city, postalCode & some time getting only County name like "India". How can i get accurate address based on latitude & longitude?. Please help me.
final List<Address> list = gCoder.getFromLocation(locationLatitude, locationLongitude, 1);
if (list != null && list.size() > 0) {
Address address = list.get(0);
StringBuilder sb = new StringBuilder();
if (address.getMaxAddressLineIndex() > 0) {
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
sb.append(address.getAddressLine(i)).append(",");
}
sb.append(address.getCountryName());
} else {
try {
sb.append(address.getAddressLine(0));
} catch (Exception ignored) {
}
}
strAddress = sb.toString();
strAddress = strAddress.replace(" ", "");
strAddress = strAddress.replace(",null", "");
strAddress = strAddress.replace("null", "");
strAddress = strAddress.replace("Unnamed", "");
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
if (!TextUtils.isEmpty(strAddress)) {
tvLocation.setText(strAddress);
Log.e("Location", strAddress + "");
}else {
Snackbar.make(getView(), "Couldn't get the location. Make sure location is enabled on the device", Snackbar.LENGTH_SHORT)
.show();
}
}
});