Как узнать название улицы из координат?
У меня есть долгота и широта в двух отдельных EditText. Я хочу, чтобы при нажатии кнопки название улицы появлялось в другом EditText.
Я пробовал сPublic Address getAddressForLocation
метод, но я не получил его на работу ..
Код
public Address getAddressForLocation(Context context, Location location) throws IOException {
if (location == null) {
return null;
}
double latitude = location.getLatitude();
double longitude = location.getLongitude();
int maxResults = 1;
Geocoder gc = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gc.getFromLocation(latitude, longitude, maxResults);
for (int i = 0; i < addresses.getMaxAddressLineIndex(); i++) {
Log.d("=Adress=",addresses.getAddressLine(i));
}
}
Как узнать название улицы из координат?
ОБНОВЛЕНИЕ (РЕШЕНИЕ)
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(LATITUDE, LONGITUDE, 1);
if (addresses != null) {
Address returnedAddress = addresses.get(0);
StringBuilder strReturnedAddress = new StringBuilder();
for (int i = 0; i < returnedAddress.getMaxAddressLineIndex(); i++) {
strReturnedAddress.append(returnedAddress.getAddressLine(i)).append("");
}
et_lugar.setText(strReturnedAddress.toString());
}
else {
et_lugar.setText("No Address returned!");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
et_lugar.setText("Canont get Address!");
}
Спасибо