我正在为我正在进行的项目制作一个指南针应用程序,该应用程序可在崎岖地形上使用。我已经使用了标准的
有人知道如何补偿这一点吗?示例代码将不胜感激。
这是我目前正在使用的代码:
感谢您的帮助,
亚当
TYPE_ACCELEROMETER
和TYPE_MAGNETIC_FIELD
传感器,并且它似乎给出了相当准确的读数。然而,当我围绕y和z轴倾斜手机时,即使手机指向相同的方向(恒定的z轴),Heading读数也会发生变化。有人知道如何补偿这一点吗?示例代码将不胜感激。
这是我目前正在使用的代码:
private void updateDirection() {
float[] R = new float[16];
float[] orientationValues = new float[3];
if(SensorManager.getRotationMatrix (R, null, accelerometerValues, magneticValues)){
SensorManager.getOrientation (R, orientationValues);
orientationValues[0] = (float)Math.toDegrees (orientationValues[0]);
orientationValues[1] = (float)Math.toDegrees (orientationValues[1]);
orientationValues[2] = (float)Math.toDegrees (orientationValues[2]);
if(orientationValues[0] < 0){
orientationValues[0] = 360 + orientationValues[0];
}
final int trueNorthHeading = NavigationUtils.getTrueNorthBearing(currentLocation, orientationValues[0]);
if(trueNorthHeading == currentHeading) {
return;
}
int accuracy = 3;
if(NavigationUtils.isSignificantHeadingChange(currentHeading, trueNorthHeading, accuracy, SIGNIFICANT_CHANGE_LIMIT)){
int headingChangeDegrees = NavigationUtils.getStearageDegree(currentHeading, trueNorthHeading);
currentHeading = trueNorthHeading;
navigationManager.headingUpdate(trueNorthHeading, Math.round(orientationValues[0]), headingChangeDegrees);
Log.d("COMPASS", "North: values[0]: " + (int)orientationValues[0]);
}
}
}
感谢您的帮助,
亚当