위도랑 경도 나오고,주소도 나와야 되는 메소드입니다.
위도랑,경도는 나오는데 주소를 못찍고 No address found가 뜨네요.
왜 이럴까요?
private void updateWithNewLocation(Location location) {
String latlongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.TextView01);
String addressString = "No address found";
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
latlongString = "위도 : " + lat + "\n경도 : " + lng;
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Geocoder gc = new Geocoder(this,Locale.getDefault());
try {
List<Address> addresses = gc.getFromLocation(latitude,longitude,1);
StringBuilder sb = new StringBuilder();
if (addresses.size() > 0) {
Address address = addresses.get(0);
for (int i = 0;i < address.getMaxAddressLineIndex();i++)
sb.append(address.getAddressLine(i)).append("\n");
sb.append(address.getLocality()).append("\n");
sb.append(address.getPostalCode()).append("\n");
sb.append(address.getCountryName()).append("\n");
addressString = sb.toString();
}
} catch (IOException e) {
e.printStackTrace();
}
} else {
latlongString = "location 발견안됨";
}
myLocationText.setText("당신의 현재 위치는 :"+latlongString+"이고 \n\n" +
"주소는 \n" + addressString + "입니다.\n\n " +
"현재 위치를 추가하실려면 추가할 주소를 입력하세요");
}



