我现在有一个需求,就是在点击的时候需要获取当前位置的X,Y坐标,我在网上查了一下,都是在OnTouchListener中做的,但我想在onclick事件中达到相同的效果,不知道怎么处理?OnTouchListener listener = new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) { /**
* Projection 用于将屏幕坐标转换为地理位置坐标
*/
int x = (int) arg1.getX();
int y = (int) arg1.getY();
currentPt = mMapView.getProjection().fromPixels(x, y);
updateMapState(arg1); /**
* 传递点击事件给MapView,sdk会自己处理缩放,平移等手势操作
*/
return false;
}
}; mMapView.setOnTouchListener(listener);
Android坐标OnTouchListenerMotionEvent
@Override
public boolean onTouch(View arg0, MotionEvent arg1) { /**
* Projection 用于将屏幕坐标转换为地理位置坐标
*/
int x = (int) arg1.getX();
int y = (int) arg1.getY();
currentPt = mMapView.getProjection().fromPixels(x, y);
updateMapState(arg1); /**
* 传递点击事件给MapView,sdk会自己处理缩放,平移等手势操作
*/
return false;
}
}; mMapView.setOnTouchListener(listener);
Android坐标OnTouchListenerMotionEvent
囧rz
private class GISGestureListener extends SimpleOnGestureListener { private Context mContext; GISGestureListener(Context context) {
mContext = context;
} /**
* 用户(轻触触摸屏后)松开,由一个1个MotionEvent ACTION_UP触发
*/
@Override
public boolean onSingleTapUp(MotionEvent e) { Toast.makeText(mContext, "SHOW " + e.getX()+" "+e.getY(), Toast.LENGTH_SHORT).show(); ; int x = (int) e.getX();
int y = (int) e.getY();
currentPt = mMapView.getProjection().fromPixels(x, y);
pop.hidePop();
popupText.setBackgroundResource(R.drawable.popup);
popupText.setText("点击选择该点为资源坐标");
pop.showPopup(BMapUtil.getBitmapFromView(popupText), currentPt, 8);
return false; }
}。
mGestureDetector = new GestureDetector(this, new GISGestureListener(this));OnTouchListener listener = new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) { /**
* Projection 用于将屏幕坐标转换为地理位置坐标
*/
//updateMapState(arg1); /**
* 传递点击事件给MapView,sdk会自己处理缩放,平移等手势操作
*/
return mGestureDetector.onTouchEvent(arg1) ;
}
};