Android的,使用硬件指南针 [英] Android, Using the hardware compass

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

问题描述

我无法找到Android的硬件指南针多的信息在那里。我一直试图设置我的标准,迫使Android的使用硬件指南针。基本上我的问题是,我想,而该设备是固定的轴承甚至更新。

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.

从我的理解,GPS就只有当你的移动更新您的轴承。我想,无论轴承要更新,如果你移动或没有。我试着在设备欺骗想着它是由以恒定10设定速度移动,但总是轴承返回0.0。

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.

我的测试(目前)设备是HTC纹身。它有一个指南针所以这不是问题。所以我的问题是,有没有办法让轴承使用硬件指南针或不更新?无论您是否移动或不?

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?

推荐答案

你见过<一个href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html\"相对=nofollow>这个例子code ?在这里,一个 SensorListener 用于查询的方向:

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

好了,这是德precated code。现在的SensorManager具有 getOrientation()方法,该方法都可以使用。这确实需要一个旋转矩阵虽然。见<一href=\"http://www.netmite.com/android/mydroid/cupcake/development/samples/Compass/src/com/example/android/compass/CompassActivity.java\"相对=nofollow>这里的一个例子。

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.

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

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