Моего требования иметь в как Google maps apps
в режиме компаса (вы можете увидеть демонстрацию, когда нажмите на current location button twice
):Вычислить верно правильно заголовок в андроиде
- В этом режиме
compass
, карты всегда повернуты под углом, так чтоbluedot arrow
всегда указывает на верхний экран.
Но я не знаю, как правильно рассчитать bearing
от azimuth, pitch, roll
значений.
public void onSensorChanged(SensorEvent sensorEvent) {
switch (sensorEvent.sensor.getType()) {
case Sensor.TYPE_ACCELEROMETER:
System.arraycopy(sensorEvent.values, 0, mAccelerometers, 0, 3);
break;
case Sensor.TYPE_MAGNETIC_FIELD:
System.arraycopy(sensorEvent.values, 0, mMagnetometers, 0, 3);
break;
default:
break;
}
float[] rotationMatrix = new float[9];
boolean success =
SensorManager.getRotationMatrix(rotationMatrix, null, mAccelerometers, mMagnetometers);
if (success) {
SensorManager.getOrientation(rotationMatrix, mOrientation);
float azimuth = Math.toDegrees(mOrientation[0]);
float pitch = Math.toDegrees(mOrientation[1]);
float roll = Math.toDegrees(mOrientation[2]);
}
// cal to updateBearing();
}
В прошивке, CLHeading
может вернуть именно истинный heading
. Есть ли класс, который имеет такую же особенность в android
или как я могу рассчитать его?
Помогает ли это? http://stackoverflow.com/q/7355679/7292819 – Gary99
@ Gary99, нет человека. – NamNH
Вы проверили [this] (http://stackoverflow.com/a/4316717/5993410) –