Reputation: 595
Hee guys,
I'm currently using a sensorlistener to make my screen adjust as a compass. However I can't zoom in or out because I am constantly updating the camera when onSensorChanged
is called. Is there any way to make it able to zoom?
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));
}
Upvotes: 3
Views: 618
Reputation: 95
You should use the currentzoom level obtained from the map instead of the static value 15. like this:
float zoom = map.getCameraPosition().zoom;
CameraPosition pos = new CameraPosition(post, zoom, tilt, bearing);
If you want to initialise the view on 15, then do this somewhere else for example when the activity starts.
Upvotes: 3