마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 맵 터치시 위도 경도 표시 질문이요

0 추천

화면의 맵을 터치했을시 그곳의 위도와 경도를 확인할 수 있도록 만들고 있습니다. 에러는 없는데 핸드폰으로 실행을 해보면 종료가 되는데 해결 방법을 몰라 이렇게 질문 드립니다. 고수님들 제발 부탁드려요 ㅠ_ㅠ

소스부분 입니다. 다른 예제들과 섞여 있는데 public boolean onTouchEvent 이 부분을 쓴 다음부터 종료가 되고있습니다. 

public class MainActivity extends Activity  implements View.OnClickListener   {
	
	static final LatLng position = new LatLng(37.509509,126.898368);
	private double lat;
	private double lng;
	private LatLng position1;
	EditText ed1, ed2;
	Button bt1, bt2;
	private GoogleMap map;
	private Marker Marker;
	private Marker Marker1;
	MapView mapView;
	Projection projection = mapView.getProjection();

	@SuppressLint({"NewApi","NewApi"})
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		
		map = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap(); 
		Marker = map.addMarker(new MarkerOptions().position(position).icon(BitmapDescriptorFactory.fromResource(R.drawable.star3)));
		map.moveCamera(CameraUpdateFactory.newLatLngZoom(position,17));
		
		bt1 = (Button)findViewById(R.id.button1);
		bt1.setOnClickListener(this);
		bt2 = (Button)findViewById(R.id.button2);
		bt2.setOnClickListener(this);
		

	}
	
	public void remove(){
		map.clear();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
	public boolean onTouchEvent(MotionEvent event, MapView mapView){
		if(event.getAction() == 1) {
			GeoPoint p = mapView.getProjection().fromPixels((int) event.getX(),(int) event.getY());
			mapView.getController().animateTo(p);
			Toast.makeText(getBaseContext(), p.getLatitudeE6() / 1E6 + "," + p.getLongitudeE6() / 1E6 , Toast.LENGTH_SHORT).show();
		}
		return false;
		
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.button1:
			remove();
			Marker = map.addMarker(new MarkerOptions().position(position).icon(BitmapDescriptorFactory.fromResource(R.drawable.star3)));
	        map.moveCamera(CameraUpdateFactory.newLatLngZoom(position,17));
	        break;
		case R.id.button2:
			LatLng position1 = new LatLng(lat, lng);
			ed1 = (EditText)findViewById(R.id.EditText1);
			ed2 = (EditText)findViewById(R.id.EditText2);
			lat = Double.parseDouble(ed1.getText().toString());
			lng = Double.parseDouble(ed2.getText().toString());
			remove();
			Marker = map.addMarker(new MarkerOptions().position(position1).icon(BitmapDescriptorFactory.fromResource(R.drawable.star5)));
	        map.moveCamera(CameraUpdateFactory.newLatLngZoom(position1,7));
	        break;
		}	
	}
}

LogCat 부분도 올려봅니다.

 

비오는 거리 (160 포인트) 님이 2013년 8월 14일 질문

1개의 답변

0 추천
 
There could be two things.
 
i) Make sure you have defined all of your Activity classes in AndroidManifest.xml class.
 
ii) Make sure you are compiling your Android project using "Google APIs" instead of "Android 2.x", If you compile using Google APIs only then It will add Google Maps classes.
 
<uses-library android:required="true" android:name="com.google.android.maps" />
 
 
<application
 
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />
 
        <activity ...
aucd29 (218,390 포인트) 님이 2013년 8월 14일 답변
...