如何旋转箭头在GoogleMap的v2中,当我们旋转手机箭头、当我们、手机、GoogleMap

2023-09-05 09:51:54 作者:报告逗比能量不足

任何人可以帮助我如何旋转在谷歌地图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
 }