如何管理覆盖在MapViewCompassDemo Android SDK中样本 [英] How to manage overlays in MapViewCompassDemo in android sdk samples

查看:115
本文介绍了如何管理覆盖在MapViewCompassDemo Android SDK中样本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MapViewCompassDemo样本从

I am using MapViewCompassDemo sample from

\add-ons\addon-google_apis-google_inc_-7\samples\MapsDemo\

旋转基于用户direction.This地图视图工作

for rotating map view based on user direction.This is working

完美如地图没有overlays.But如果我添加覆盖映射ONTAP工作不完全相同

perfectly if the map is without overlays.But if i add overlays to map the ontap not working exactly

标记上,而rotating.can任何一个可以帮助我关于这个。

on marker while rotating.can any one help me regarding this.

推荐答案

在此示例中,只转动dispatchDraw方法only.Along与dispatchDraw旋转

in this sample it only rotate dispatchDraw method only.Along with dispatchDraw rotate

dispatchTouchEvent also.find低于code也转动toouch事件

dispatchTouchEvent also.find below code to rotate toouch events also

  @Override
    public void dispatchDraw(Canvas canvas) {
        canvas.save();
        canvas.rotate(getRotation(), getWidth() / 2, getHeight() / 2);
        super.dispatchDraw(canvas);
        canvas.restore();
    }

@Override
    public boolean dispatchTouchEvent(MotionEvent event) {
        float[] coords = new float[] {
                event.getX(), event.getY()
        };
        adjustCoords(coords, getRotation());
        MotionEvent evt = MotionEvent.obtain(event.getDownTime(), event.getEventTime(), event
                .getAction(), coords[0], coords[1], event.getPressure(), event.getSize(), event
                .getMetaState(), event.getXPrecision(), event.getYPrecision(), event.getDeviceId(),
                event.getEdgeFlags());
        return super.dispatchTouchEvent(evt);
    }
    protected void adjustCoords(float[] coords, float deg) {
        float x = coords[0];
        float y = coords[1];
        int centerX = getWidth() / 2;
        int centerY = getHeight() / 2;
        // convert to radians
        float rad = (float) ((deg * Math.PI) / 180F);
        float s = (float) Math.sin(rad);
        float c = (float) Math.cos(rad);
        // translate point back to origin:
        x -= centerX;
        y -= centerY;
        // apply rotation
        float tmpX = x * c - y * s;
        float tmpY = x * s + y * c;
        x = tmpX;
        y = tmpY;
        // translate point back:
        x += centerX;
        y += centerY;
        coords[0] = x;
        coords[1] = y;
    }

请参阅此下面的链接

http://evancharlton.com/thoughts/android-rotating-touch-events /

这篇关于如何管理覆盖在MapViewCompassDemo Android SDK中样本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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