0
私は以下のコードを、人間が読める長いアドレスに変換することができます。今、私は、アドレス、市、郵便番号&を含むアドレスの完全な詳細を取得していて、「インド」のような郡名のみを取得しています。どのように私は緯度&経度に基づいて正確なアドレスを取得できますか? 私を助けてください。 Geocoder
オブジェクトから緯度、経度からジオコーディングされた住所を取得するにはどうすればよいですか?
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();
}
}
});
ここで確認できます。 https://stackoverflow.com/a/9409229/5580210 –