Android的指南针例如 [英] Android compass example

查看:141
本文介绍了Android的指南针例如的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找为Android指南针的例子。所有我需要做的是获得正确的方位(纵向和放大器;横向模式)。

I'm searching for a compass example for Android. All I need to do is to get the correct bearing (in portrait & landscape mode).

我已经发现了几个样品,只有一些使用 Sensor.TYPE_ORIENTATION ,有些用 Sensor.TYPE_ACCELEROMETER 的组合&放大器; Sensor.TYPE_MAGNETIC_FIELD

I already found several samples, some use only Sensor.TYPE_ORIENTATION, some use a combination of Sensor.TYPE_ACCELEROMETER & Sensor.TYPE_MAGNETIC_FIELD.

这是正确的&放大器;获得轴承常见的方式为我们说的Andr​​oid 1.6 - 4.0

Which is the correct & common way to get the bearing for let's say Android 1.6 - 4.0?

推荐答案

Sensor.TYPE_ORIENTATION 是德precated。该文件说,你应该使用 SensorManager.getOrientation()代替。所以,你应该从 Sensor.TYPE_ACCELEROMETER ,以及从 Sensor.TYPE_MAGNETIC_FIELD 读,然后调用 SensorManager.getRotationMatrix()最后 SensorManager.getOrientation()将返回你手机的方向。从那里,如果你看到这个图是微不足道拿到手机的方向。这可能是你的第二个例子呢,但我不知道,因为你没有告诉我它是什么。

Sensor.TYPE_ORIENTATION is deprecated. The documentation says you should use SensorManager.getOrientation() instead. So you should read from Sensor.TYPE_ACCELEROMETER as well as from Sensor.TYPE_MAGNETIC_FIELD, and then call SensorManager.getRotationMatrix() and finally SensorManager.getOrientation() which will return you the orientation of the phone. From there if you see this diagram it is trivial to get the phone's orientation. This is probably what your second example does, but I don't know because you didn't show me what it is.

这篇关于Android的指南针例如的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆