Android compass example does not seem to work in landscape mode

左心房为你撑大大i 提交于 2019-12-23 04:07:14

问题


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

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?

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

Best regards

P


回答1:


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 ));


来源:https://stackoverflow.com/questions/4065632/android-compass-example-does-not-seem-to-work-in-landscape-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!