안드로이드 개발 질문/답변
(글 수 45,052)
코드는 아래와 같은데요.
try에서 IOException이 나네요.
DDMS에서 위도/경도는 는 잘 받아옵니다.
private void updateWithNewLocation(Location location) {
String latlongString;
TextView myLocationText;
myLocationText = (TextView)findViewById(R.id.myLocationText);
String addressString = "No address found";
if (location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
latlongString = "위도 : " + latitude + "\n경도 : " + longitude;
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) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
{
latlongString = "location 발견안됨";
}
myLocationText.setText("당신의 현재 위치는 \n" + latlongString + "이고 \n\n" +
"주소는 \n" + addressString + "입니다");
}