如何式TYPE_ACCELEROMETER和TYPE_MAGNETIC_FIELD用来制造Android设备上的指南针 [英] How type TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD used to make compass on android devices

查看:755
本文介绍了如何式TYPE_ACCELEROMETER和TYPE_MAGNETIC_FIELD用来制造Android设备上的指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,它使用的应用程序指南针虽然我成功地实现了它,但没有这样简单的解释是它是如何工作。怎么样的 TYPE_ACCELEROMETER TYPE_MAGNETIC_FIELD 被用来获取方向。我知道我们没有得到它,我们得到了数组的零指数是方位从中我们拿到学位,来到知道北方。但如何得到它的这一切。 任何人能解释吗?

I am working on an application which uses compass although I successfully implemented it but there is no such brief explanation that how it works. Like how the TYPE_ACCELEROMETER and TYPE_MAGNETIC_FIELD was used to get the orientation. I know we did get it and the zero index of the array we got is the azimuth from which we get the degree and came to know where north is. But how it get to this all. Can anyone explain please?

其次,如果我把我的手机在地板上假设它在北美的方向指向,当它被放在地面是什么现在我拿起​​我的手机不放I 颠倒会发生,为什么呢?

Secondly what if I place my mobile on the floor suppose it points in the direction of north when it is placed on ground now I take up my mobile and hold I upside down what will happen and why?

据我的理解方向不应该改变。我可能是错的,任何人都可以请指导我在此。非常感谢。

According to my understanding the direction shouldn't changed. I might be wrong, can anyone please guide to me on this. Thanks a lot.

推荐答案

您既需要 Magnectic领域加速度计算罗盘方向。你可以看到为什么如果你读的 getRotationMatrix 或更详细的说明,请参见<一个源$ C ​​$ C href=\"http://stackoverflow.com/questions/15315129/convert-magnetic-field-x-y-z-values-from-device-into-global-reference-frame/15317814#15317814\">Convert磁场X,Y,Z值从设备到全球参照系

You need both the Magnectic field and Accelerometer to calculate the compass direction. You can see why if you read the source code of the getRotationMatrix or for a more verbose explanation see Convert magnetic field X, Y, Z values from device into global reference frame

如果你站在同一个地方,磁场不会改变。即在onSensorChanged返回应该改变非常小的磁场矢量。这并不是说改变向量而是改变设备的坐标。这是什么被计算并调用罗盘方向,混淆你的意思。在这种情况下被用作罗盘方向的方向 y坐标的方向。因此,当你垂直握住手机时, y坐标指向天空或地面,并没有什么意义谈罗盘方向

If you stand at the same place, the magnetic field does not change. That is the magnetic field vector returned in onSensorChanged should change very little. It is not the vector that change but the coordinates of the device that change. It is the meaning of what is being calculate and call the "compass direction" that confuses you. In this case the direction to be used as the "compass direction" is the direction of the y coordinate. Thus when you hold the phone vertically, the y coordinate points to the sky or the ground and it does not make sense to talk about "compass direction"

这篇关于如何式TYPE_ACCELEROMETER和TYPE_MAGNETIC_FIELD用来制造Android设备上的指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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