Android的指南针例子似乎并没有在横向模式下工作并没有、指南针、横向、例子

2023-09-07 13:03:41 作者:心死

我已经开发了基于这个例子指南针:http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html

I have developed a compass based on this example: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html

由于我的应用程序只能在横向模式因此将罗盘工作。然而,似乎因为这code没有在横向模式下正常工作。北点多向东。如果我运行Android例如code,我得到了同样的问题。

Since my app only operates in landscape mode so will the compass. However, it seems as this code does not function correctly in landscape mode. North points more towards east. If i run the Android example code I get the same issue.

有没有其他人注意到这一点,更是没有人有办法解决吗?

Has anyone else noticed this and even better does anyone have a solution?

顺便说一句,我在Nexus One的测试这一点。不知道这是一个手机相关的问题。

By the way, I am testing this on a Nexus One. Not sure if this is a phone related issue.

最好的问候

P

推荐答案

您必须从旋转减去90度,因为magnometer是在手机的顶部。

You have to subtract 90 degrees from the rotation because the magnometer is on the top of the phone.

int test = getResources().getConfiguration().orientation;
if(Configuration.ORIENTATION_LANDSCAPE == test) {
            rotation = -90f;
        }
        else {
            rotation = 0f;
        }
canvas.rotate((float) (-Math.toDegrees(mOrientation[0]) + rotation ));