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
}