OnSensorChanged Google Map Rotate

there is something wrong with onSensorChange , I managed to move my map from the north, my code was right, but it always rotates even the phone without moving

  @Override protected void onResume() { mSensorManager = (SensorManager)getSystemService(SENSOR_SERVICE); mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); mMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD); super.onResume(); mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_STATUS_ACCURACY_LOW); mSensorManager.registerListener(this, mMagnetometer, SensorManager.SENSOR_STATUS_ACCURACY_LOW); } @Override public void onSensorChanged(SensorEvent event) { if (event.sensor == mAccelerometer) { System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length); mLastAccelerometerSet = true; } else if (event.sensor == mMagnetometer) { System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length); mLastMagnetometerSet = true; } if (mLastAccelerometerSet && mLastMagnetometerSet) { final Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer); SensorManager.getOrientation(mR, mOrientation); float azimuthInRadians = mOrientation[0]; float azimuthInDegress = (float)(Math.toDegrees(azimuthInRadians)+360)%360; RotateAnimation ra = new RotateAnimation( mCurrentDegree, -azimuthInDegress, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); updateCamera(azimuthInDegress); } }, 3000); } } private void updateCamera(final Float bearing) { CameraPosition pos = CameraPosition.builder().target(latLng).zoom(20).bearing(bearing).build(); mGoogleMap.moveCamera(CameraUpdateFactory.newCameraPosition(pos)); } 

I already put a delay of 5 seconds, but did not work, please help me thanks

+1
java android-studio google-maps compass android-sensors
source share

No one has answered this question yet.

See similar questions:

7
ROTATE Google-Map to display my DIRECTIONS in real time

or similar:

3073
How to efficiently iterate over each entry on a Java map?
1544
Sort map <Key, value> by value
1070
How can I initialize a static map?
634
JS API Google v3 API - Simple Multiple Token Example
528
How to disable mouse wheel scaling using the Google Maps API
403
Google Maps API v3: How to remove all markers?
369
Launching Google Maps Directions through Android Intention
345
Google Maps and JavaFX: Displaying a marker on the map after clicking the JavaFX button
3
How to read the heart rate from Android Wear
2
The right combination of touch control and camera on Android

All Articles