枪王放大的GoogleMaps活动 [英] Double Tap Zoom in GoogleMaps Activity

查看:154
本文介绍了枪王放大的GoogleMaps活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  

可能重复:
  枪王 - >变焦Android上的MapView?

我是新手的Andr​​oid开发者。我正在开发中,我使用谷歌地图的应用程序。我要实现双击放大的GoogleMaps。当我双击在地图上应该放大。请,如果有可能提供样本code。
我写了下面的code,但我不知道该怎么添加更多。

 公共类地图扩展MapActivity实现OnGestureListener,OnDoubleTapListener {

    私人GestureDetector检测器;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        //服务器MapViewer MapViewer的=新的MapViewer(NULL,NULL);
        图形页面图形页面=(图形页面)findViewById(R.id.mapview);
        探测器=新GestureDetector(这一点,这一点);
        mapView.setBuiltInZoomControls(真正的);
    }

    @覆盖
    保护的布尔isRouteDisplayed(){
        返回false;
    }

    公共布尔onDoubleTap(MotionEvent E){
        。mapView.getController()zoomIn();
        返回false;
    }

    公共布尔onDoubleTapEvent(MotionEvent E){
        返回false;
    }

    公共布尔onSingleTapConfirmed(MotionEvent E){
        返回false;
    }

    公共布尔onDown(MotionEvent E){
        返回false;
    }

    公共布尔onFling(MotionEvent E1,E2 MotionEvent,浮velocityX,浮velocityY){
        返回false;
    }

    公共无效onLong preSS(MotionEvent E){
    }

    公共布尔onScroll(MotionEvent E1,E2 MotionEvent,浮distanceX,浮distanceY){
        返回false;
    }

    公共无效OnShow中preSS(MotionEvent E){
    }

    公共布尔onSingleTapUp(MotionEvent E){
        返回false;
    }
}
 

解决方案

根据这里的信息提供和<一href="http://stackoverflow.com/questions/4454456/double-click-tap-map-zoom-android/9918657#9918657">double点击/点击地图缩放(安卓)我得到了最好的解决办法是:

  myLocationOverlay =新MyLocationOverlay(本,图形页面);

MyItemizedOverlay itemizedOverlay =新MyItemizedOverlay(){
    专用长SYSTEMTIME = System.currentTimeMillis的();

    @覆盖
    公共布尔的onTouchEvent(MotionEvent事件,图形页面图形页面){
        开关(event.getAction()){
        案例MotionEvent.ACTION_DOWN:
            如果((System.currentTimeMillis的() -  SYSTEMTIME)所述; ViewConfiguration.getDoubleTapTimeout()){
                mapController.zoomInFixing((int)的event.getX(),(int)的event.getY());
            }
            打破;
        案例MotionEvent.ACTION_UP:
            SYSTEMTIME = System.currentTimeMillis的();
            打破;
        }

        返回false;
    }
};
 

情况下MotionEvent.ACTION_UP 加入作为如何<一个结果href="https://developer.android.com/reference/android/view/ViewConfiguration.html#getDoubleTapTimeout%28%29" rel="nofollow">https://developer.android.com/reference/android/view/ViewConfiguration.html#getDoubleTapTimeout()说 getDoubleTapTimeout()将被计算。此外,我改变了变焦功能,因为这一个是最少的跳动和功能相同的地图应用程序。

Possible Duplicate:
Double Tap -> Zoom on Android MapView?

I am newbie Android developer. I am developing an application in which I am using GoogleMaps. I have to implement double tap zoom in GoogleMaps. When I double click on the map it should zoom in. Kindly if it is possible provide a sample code.
I have written the following code but I dont know what to add more.

public class Maps extends MapActivity implements OnGestureListener, OnDoubleTapListener {

    private GestureDetector detector;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        // MapViewer mapViewer = new MapViewer(null, null);
        MapView mapView = (MapView) findViewById(R.id.mapview);
        detector = new GestureDetector(this, this);
        mapView.setBuiltInZoomControls(true);
    }

    @Override
    protected boolean isRouteDisplayed() {
        return false;
    }

    public boolean onDoubleTap(MotionEvent e) {
        mapView.getController().zoomIn();
        return false;
    }

    public boolean onDoubleTapEvent(MotionEvent e) {
        return false;
    }

    public boolean onSingleTapConfirmed(MotionEvent e) {
        return false;
    }

    public boolean onDown(MotionEvent e) {
        return false;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        return false;
    }

    public void onLongPress(MotionEvent e) {
    }

    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        return false;
    }

    public void onShowPress(MotionEvent e) {
    }

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

解决方案

Based on the information provided here and double click/tap map zoom (Android) the best solution I got was:

myLocationOverlay = new MyLocationOverlay(this, mapView);

MyItemizedOverlay itemizedOverlay = new MyItemizedOverlay() {
    private long systemTime = System.currentTimeMillis();

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            if ((System.currentTimeMillis() - systemTime) < ViewConfiguration.getDoubleTapTimeout()) {
                mapController.zoomInFixing((int) event.getX(), (int) event.getY());
            }
            break;
        case MotionEvent.ACTION_UP:
            systemTime = System.currentTimeMillis();
            break;
        }

        return false;
    }
};

case MotionEvent.ACTION_UP was added as a result of how https://developer.android.com/reference/android/view/ViewConfiguration.html#getDoubleTapTimeout() says getDoubleTapTimeout() is to be calculated. Additionally I changed the zoom function as this one is the least jumpy and functions identical to the Maps app.

这篇关于枪王放大的GoogleMaps活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆