如何旋转箭头在GoogleMap的v2中,当我们旋转手机 [英] How to rotate arrow head in googlemap v2 when we rotate the phone

查看:280
本文介绍了如何旋转箭头在GoogleMap的v2中,当我们旋转手机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人可以帮助我如何旋转在谷歌地图V2的箭头?你已经看到,在nevigation的箭头旋转到我们所面对的方向。我想要实现我的应用程序。我红约 markerOption.rotation(旋转)这似乎是静态的。我想动态旋转箭头时,我旋转手机。

Can anybody help me with how to rotate the arrow head in google map v2? You have seen that in nevigation the arrow head is rotating to the direction we face. I want to implement that to my app. I red about markerOption.rotation(rotation) this seems a static one. I want to rotate the arrow dynamically when I rotate the phone.

推荐答案

我能做到这一点。它是如此容易。下面是如何。 这是为了读出传感器和得到的电话的取向。

I was able to do that. Its so easy. below is how. This is to read the sensor and get the orientation of the phone.

/**
 * Initialize the sensor manager.
 */
private void setupSensorManager() {
    mSensorManager = (SensorManager) mContext
            .getSystemService(Context.SENSOR_SERVICE);
    mSensorManager.registerListener(mSensorListener,
            mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
            SensorManager.SENSOR_DELAY_NORMAL);

    Log.d(TAG, "SensorManager setup");
}

/**
 * The sensor event listener.
 */
SensorEventListener mSensorListener = new SensorEventListener() {

    @Override
    public void onSensorChanged(SensorEvent event) {
        mOrientation = event.values[0];
        Log.d(TAG, "Phone Moved "+mOrientation);
        draw(mOrientation);
    }

    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }
};

而这正是我真的旋转。我的标记已添加到地图中。而我从另一个类访问它。

And this is where I really rotate. My marker is already added to the map. And I am accessing it from another class.

public void draw(float angle) {
            // Take the relevant Marker from the marker list where available in map
    AndroidMapGoogleOverlayItem myself = (AndroidMapGoogleOverlayItem) getOverlayItem(0);

    if (myself == null) {
        return;
    }
    myself.getMarker().setRotation(mOrientation);  // set the orientation value returned from the senserManager
 }

这篇关于如何旋转箭头在GoogleMap的v2中,当我们旋转手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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