嘻嘻,
我目前正在使用一个传感器监听器来调整我的屏幕作为指南针。但是我不能放大或缩小,因为当调用onSensorChanged
时,我一直在更新相机。有什么方法可以使它变焦吗?
private SensorEventListener mySensorEventListener = new SensorEventListener() {
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
@Override
public void onSensorChanged(SensorEvent event) {
if(routeStarted == true)
{
if(event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
SensorManager.getRotationMatrixFromVector(
mRotationMatrix , event.values);
float[] orientation = new float[3];
SensorManager.getOrientation(mRotationMatrix, orientation);
float bearing = (float) (Math.toDegrees(orientation[0]) + mDeclination);
float tilt = 30;
updateCamera(bearing, tilt);
}
}
}
};
private void updateCamera(float bearing, float tilt) {
// TODO Auto-generated method stub
LatLng post = new LatLng(mGoogleMap.getMyLocation().getLatitude(), mGoogleMap.getMyLocation().getLongitude());
CameraPosition pos = new CameraPosition(post, 15, tilt, bearing);
mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos));
}
最佳答案
您应该使用从映射获得的currentzoom级别,而不是静态值15。这样地:
float zoom = map.getCameraPosition().zoom;
CameraPosition pos = new CameraPosition(post, zoom, tilt, bearing);
如果要在15上初始化视图,请在其他地方(例如活动开始时)执行此操作。
关于android - Android Google Maps无法在罗盘处于 Activity 状态时进行缩放,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26800344/