gpt4 book ai didi

android - 旋转手机时如何在googlemap v2中旋转箭头

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:16 24 4
gpt4 key购买 nike

谁能帮我解决如何在 google map v2 中旋转箭头?您已经看到,在航行中,箭头旋转到我们面对的方向。我想在我的应用程序中实现它。我对 markerOption.rotation(rotation) 很感兴趣,这似乎是一个静态的。我想在旋转手机时动态旋转箭头。

最佳答案

我做到了。它是如此容易。下面是如何。这是为了读取传感器并获取手机的方向。

/**
* 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) {
}
};

这才是我真正轮换的地方。我的标记已添加到 map 中。我正在从另一个类(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
}

关于android - 旋转手机时如何在googlemap v2中旋转箭头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19826543/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com