안드로이드 개발 질문/답변
(글 수 45,052)
public boolean onTouchEvent(MotionEvent event, MapView mapView)
{
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
String add="";
try {
Iterator<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1).iterator();
if (addresses != null)
{
while(addresses.hasNext()) {
Address namedLoc = addresses.next();
String placeName = namedLoc.getLocality();
String featureName = namedLoc.getFeatureName();
String country = namedLoc.getCountryName();
String road = namedLoc.getThoroughfare();
add += String.format("\n[%s][%s][%s][%s]", placeName, featureName, road, country);
int addidx = namedLoc.getMaxAddressLineIndex();
for (int idx = 0 ; idx <= addidx ; idx++)
{
String addLine = namedLoc.getAddressLine(idx);
add += String.format("\nLine %d: %s", idx, addLine);
}
}
}
/* String lalg;
lalg = p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6()/1E6;
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show(); */
}
catch (IOException e){
e.printStackTrace();
}
return true;
}
else
return false;
}
터치시 터치부분의 주소를 텍스트로 띄울려고 하는데 전혀 뜨지를 않네요; 실행하는것에는 전혀 문제가 되지를 않습니다.
다만 주소가 뜨지를 않습니다.
{
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
String add="";
try {
Iterator<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6()/1E6, p.getLongitudeE6()/1E6, 1).iterator();
if (addresses != null)
{
while(addresses.hasNext()) {
Address namedLoc = addresses.next();
String placeName = namedLoc.getLocality();
String featureName = namedLoc.getFeatureName();
String country = namedLoc.getCountryName();
String road = namedLoc.getThoroughfare();
add += String.format("\n[%s][%s][%s][%s]", placeName, featureName, road, country);
int addidx = namedLoc.getMaxAddressLineIndex();
for (int idx = 0 ; idx <= addidx ; idx++)
{
String addLine = namedLoc.getAddressLine(idx);
add += String.format("\nLine %d: %s", idx, addLine);
}
}
}
/* String lalg;
lalg = p.getLatitudeE6()/1E6 + "," + p.getLongitudeE6()/1E6;
Toast.makeText(getBaseContext(), add, Toast.LENGTH_SHORT).show(); */
}
catch (IOException e){
e.printStackTrace();
}
return true;
}
else
return false;
}
터치시 터치부분의 주소를 텍스트로 띄울려고 하는데 전혀 뜨지를 않네요; 실행하는것에는 전혀 문제가 되지를 않습니다.
다만 주소가 뜨지를 않습니다.
2010.10.25 14:24:12
우선 답변을 주셔서 감사합니다.
그런데 위경도는 뜨는데 주소만 뜨지않는게 이상해서요. 주소 부분만 안뜬다는게 이상하네요.;;
혹시 에뮬에서는 주소부분을 못받아온다던가 그런지는 않지요?
// 위의 코드로는 위경도 안뜨고요. 위경도 표시되게 수정했을때는 잘 뜹니다.
그런데 위경도는 뜨는데 주소만 뜨지않는게 이상해서요. 주소 부분만 안뜬다는게 이상하네요.;;
혹시 에뮬에서는 주소부분을 못받아온다던가 그런지는 않지요?
// 위의 코드로는 위경도 안뜨고요. 위경도 표시되게 수정했을때는 잘 뜹니다.
2010.10.25 18:30:21
제가 질문을 잘못 이해한것 같네요.
아마도 위치한 곳이 address가 없는 곳일 경우 주소가 안뜨는데... 혹시 바다?
그렇지 않다면 화면 내에 터치 이벤트가 들어오는지 부터 보세요?
에뮬이라면 위도 경도 가상 해주셨나요?
2010.10.26 09:40:07
에뮬은 써보지 않아서...
헐 에뮬 문제인가?
http://www.mail-archive.com/android-developers@googlegroups.com/msg110754.html
인터넷을 찾아보니 2.1에서는 된다고 하는것 같은데 2.1로 해보세요.




controller를 띄우셨나요?
setBuiltInZoomControls(true); 이 메소드를 쓸 경우
터치 부분이 먹통이 됩니다. 그래서
메소드로 컨트롤러를 띄우는게 아니라 컨트롤러를 따로 넣어 줘야 합니다.
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.layout_zoom); View zoomView = mapView.getZoomControls(); MapView.LayoutParams params = new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, mapView.getWidth() /2 , mapView.getHeight(), MapView.LayoutParams.CENTER); zoomLayout.addView(zoomView, params);