Android,使用硬件指南针

发布于 2024-09-03 20:09:41 字数 264 浏览 3 评论 0原文

我找不到关于 Android 硬件指南针的太多信息。我一直在尝试设置我的标准来强制 Android 使用硬件指南针。基本上我的问题是我希望即使设备静止时轴承也能更新。

据我了解,GPS 只会在您移动时更新您的方位。无论您是否搬家,我都愿意更新。我尝试通过将速度设置为常数 10 来欺骗设备,使其认为它正在移动,但轴承始终返回 0.0。

我的测试设备(当前)是 HTC Tattoo。它有一个指南针,所以这不是问题。所以我的问题是,有没有办法使用硬件罗盘来更新方位?不管你搬还是不搬?

I can't find much information out there on Android's hardware compass. I keep trying to setup my criteria to force Android to use the hardware compass. Basically my problem is I want the bearing to update even while the device is stationary.

From my understanding the GPS will only update your bearing when your moving. I'd like bearing to update regardless if you're moving or not. I've tried tricking the device in to thinking it's moving by setting the speed at a constant 10 but the bearing returns 0.0 always.

My device for testing (currently) is a HTC Tattoo. It has a compass so that's not the problem. So my question is, is there a way to get the bearing to update using hardware compass or not? regardless if your moving or not?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜妞爱困 2024-09-10 20:09:41

您看过这个示例代码吗?这里使用 SensorListener 来查询方向:

mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mListener = new SensorListener() {
    public void onSensorChanged(int sensor, float[] values) {
        if (Config.LOGD) Log.d(TAG, "sensorChanged (" + values[0] + ", " + values[1] + ", " + values[2] + ")");
        mValues = values;
        if (mView != null) {
            mView.invalidate();
        }
    }
mSensorManager.registerListener(mListener, 
                    SensorManager.SENSOR_ORIENTATION,
                    SensorManager.SENSOR_DELAY_GAME);

好的,所以这是已弃用的代码。现在 SensorManager 有一个可以使用的 getOrientation() 方法。但这确实需要一个旋转矩阵。请参阅此处举个例子

Have you seen this example code? Here a SensorListener is used to query the orientation:

mSensorManager = (SensorManager)getSystemService(Context.SENSOR_SERVICE);
mListener = new SensorListener() {
    public void onSensorChanged(int sensor, float[] values) {
        if (Config.LOGD) Log.d(TAG, "sensorChanged (" + values[0] + ", " + values[1] + ", " + values[2] + ")");
        mValues = values;
        if (mView != null) {
            mView.invalidate();
        }
    }
mSensorManager.registerListener(mListener, 
                    SensorManager.SENSOR_ORIENTATION,
                    SensorManager.SENSOR_DELAY_GAME);

Ok, so this is deprecated code. Now the SensorManager has a getOrientation() method that can be used. This does need a rotation matrix though. See here for an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文