我想制作一个响应双击的地图视图并获取单击位置的地理点并将其返回给调用者活动。我在 Eclipse 模拟器中测试我的应用程序,但是当我双击地图时没有任何反应,我的 onDoubleTap() 方法从不进入
这是我的代码
public class MYMapActivity extends MapActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener{
GestureDetector gestureDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mymapview);
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
gestureDetector = new GestureDetector(getApplicationContext(), this);
gestureDetector.setOnDoubleTapListener(this);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
public boolean onDoubleTap(MotionEvent mev) {
MapView mapView = (MapView) findViewById(R.id.mapview);
Projection p = mapView.getProjection();
GeoPoint geoPoint = p.fromPixels((int) mev.getX(), (int) mev.getY());
int latitude = geoPoint.getLatitudeE6();
int longitude = geoPoint.getLongitudeE6();
Intent resultIntent = new Intent();
resultIntent.putExtra("latitude", latitude);
resultIntent.putExtra("longitude", longitude);
setResult(Activity.RESULT_OK, resultIntent);
finish();
return true;
}
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onDown(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onLongPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
float distanceY) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent e) {
// TODO Auto-generated method stub
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
// TODO Auto-generated method stub
return false;
}
}
有什么问题或错过了什么让我的双击永远不会触发?