マピオンAPI


Android Maps APIドキュメント

ダブルタップで地図画像を1.5倍拡大する

public class MainActivity extends MapActivity {

	MapView mapView;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mapView = new MapView(this, "APIキー");
		setContentView(mapView);
		
		mapView.setClickable(true);
		mapView.setBuiltInZoomControls(true);
		
		mapView.getOperatorOverlays().add(new ZoomOperatorOverlay());
	}
}
public class ZoomOperatorOverlay extends Overlay {

	private GestureDetector gestureDetector;
	
	private float scalex = 1f;
	private float scaley = 1f;
	
	public ZoomOperatorOverlay() {
		gestureDetector = new GestureDetector(new SimpleOnGestureListener() {
			
			@Override 
			public boolean onDoubleTap(MotionEvent event) { 	
				if (scalex == 1f) {
					scalex = 1.5f;
					scaley = 1.5f;
				} else {
					scalex = 1f;
					scaley = 1f;
				}
				
				return super.onDoubleTap(event); 
			} 
			
			@Override 
			public void onLongPress(MotionEvent event) { 
				super.onLongPress(event); 
			} 
			
			@Override
            public boolean onDown(MotionEvent e) {
                return false;
            }
			
			@Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2,
            		float distanceX, float distanceY) {
                return true;
            }

			@Override
            public boolean onSingleTapUp(MotionEvent e) {
				return false;
            }

			@Override
            public boolean onFling(MotionEvent e1, MotionEvent e2,
            		float velocityX, float velocityY) {
                return false;
            }
        });
		gestureDetector.setIsLongpressEnabled(true);
		
	}
	
	@Override
	public boolean onTouchEvent(MotionEvent e, MapView mapView) {
		gestureDetector.onTouchEvent(e);
		return false;

	}

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean flag) {
		canvas.scale(scalex, scaley, ViewRectangle.getViewWidth() / 2, ViewRectangle.getViewHeight() / 2);
    }
}