注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

gmd20的个人空间

// 编程和生活

 
 
 

日志

 
 

为自己的Android手机写个指南针  

2010-08-18 20:19:38|  分类: 程序设计 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

刚刚去看摩托罗拉的官网上去看一下,我新买的手机应该是有compass传感器的。

去看了一下Android的网站去看了一下,要写个指南针,应该需要加速传感器与电磁两个传感器。


Sensor.TYPE_ORIENTATION
:

All values are angles in degrees.

values[0]: Azimuth, angle between the magnetic north direction and the Y axis, around the Z axis (0 to 359). 0=North, 90=East, 180=South, 270=West

values[1]: Pitch, rotation around X axis (-180 to 180), with positive values when the z-axis moves toward the y-axis.

values[2]: Roll, rotation around Y axis (-90 to 90), with positive values when the x-axis moves toward the z-axis.

Important note: For historical reasons the roll angle is positive in the clockwise direction (mathematically speaking, it should be positive in the counter-clockwise direction).

Note: This definition is different from yaw, pitch and roll used in aviation where the X axis is along the long side of the plane (tail to nose).

Note: This sensor type exists for legacy reasons, please use
getRotationMatrix()
in conjunction with
remapCoordinateSystem()
and
getOrientation()
to compute these values instead.


Sensor.TYPE_ACCELEROMETER
:

All values are in SI units (m/s^2) and measure the acceleration applied to the phone minus the force of gravity.

values[0]: Acceleration minus Gx on the x-axis

values[1]: Acceleration minus Gy on the y-axis

values[2]: Acceleration minus Gz on the z-axis

Examples:


When the device lies flat on a table and is pushed on its left side toward the right, the x acceleration value is positive.
When the device lies flat on a table, the acceleration value is +9.81, which correspond to the acceleration of the device (0 m/s^2) minus the force of gravity (-9.81 m/s^2).
When the device lies flat on a table and is pushed toward the sky with an acceleration of A m/s^2, the acceleration value is equal to A+9.81 which correspond to the acceleration of the device (+A m/s^2) minus the force of gravity (-9.81 m/s^2).


Sensor.TYPE_MAGNETIC_FIELD
:

All values are in micro-Tesla (uT) and measure the ambient magnetic field in the X, Y and Z axis.

应该是直接监听 Sensor.TYPE_ORIENTATION: 这个传感器就可以了,好像文档又说仅仅为了解决遗留问题,然后推荐使用getRotationMatrix()
getOrientation()
函数来做到同样的功能。不过这样也还是要监控下面两个传感器才行啊,要获取两个传给getRotationMatrix() 的矩阵。

竟然可以用,还不如直接使用Sensor.TYPE_ORIENTATION: 来的方便,谁叫你遗留在那里,呵呵!

有空下载个Android的SDK回来试试。

关键的类:

android.hardware.SensorEvent
android.hardware.SensorManager

  评论这张
 
阅读(787)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017