How to get high quality compass orientation (like in Google Maps)?

All the compass tuning guides in Android that I found have an error: when you hold the phone in portrait mode and "look" above the horizon, the compass needle rotates 180 degrees in the right direction.

Google Maps orientation pointer does not have this problem.

Another nice thing that Google Maps have is that they somehow evaluate the accuracy of the compass. Any idea how they do it?

+6
source share
4 answers
  • Error viewing over the horizon.

. , , , .

https://www.journal.deviantdev.com/android-compass-azimuth-calculating/

: ", ( 45 °), remapCoordinateSystem() ".

  1. .

, , . - . Samsung LG, Android System .

, : . , .

, . , ( , , GPS).

  • . , . , , , , 5 .

  • . android . , Android. Harward , , , . , Android , , , - , ().

, (/), Android 20, 50, 1000... , , .

- , , , .

+3

, , - Gimbal Lock.

, , . (AR- > 25 || < 155) x, y x, z. .

SensorManager.getRotationMatrixFromVector(rotationMatrix, event.values);
SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRM);
SensorManager.getOrientation(remappedRM, orientation);

Gimbal Lock, , 3D- ( - , x, y Gimbal Lock), Play Store, , . 10 . . 1-5 , , 10 , .

Google . .

currentLocation.getBearing();

( ) - , .

  • GPS/Wife (Google ) .
  • ( , , ), ( + + ) ,
  • / + . , , , ( , ).
+3

, , . , , , , . , , . , , , . , , . , . .

, . , , - , - .

+2

Ok, I figured it out myself. First you need to calculate the bearing from the compass. then you can rotate the Maps api-2 camera.

public void updateCamera(float bearing) {
            CameraPosition currentPlace = new CameraPosition.Builder()
                    .target(new LatLng(centerLatitude, centerLongitude))
                    .bearing(bearing).tilt(65.5f).zoom(18f).build();
            googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));

    }

set SensorListener to your code and call this method in the onSensorChanged event. I added a slope value to make the map rotate in 3D.

[Link:] [ Android maps v2 rotate mapView using compass 1

if you can find out more http://www.techotopia.com/index.php/Working_with_the_Google_Maps_Android_API_in_Android_Studio

+1
source

All Articles