
我是Android的新手,我想根据我的相机获得方向.如何根据相机获取方向信息?你能给出一个想法吗?
解决方法:
不推荐使用TYPE_ORIENTATION
我们不能再使用方向传感器,我们可以串联使用磁场传感器和加速计传感器来获得相同的功能.这是更多的工作,但它允许继续使用回调来处理方向更改.
这是指南针示例:
http://www.codingforandroid.com/2011/01/using-orientation-sensors-simple.html
从加速度计和磁场到azimut的转换:
float[] mGravity;float[] mGeomagnetic;public voID onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) mGravity = event.values; if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic = event.values; if (mGravity != null && mGeomagnetic != null) { float R[] = new float[9]; float I[] = new float[9]; if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) { // orIEntation contains azimut, pitch and roll float orIEntation[] = new float[3]; SensorManager.getorIEntation(R, orIEntation); azimut = orIEntation[0]; } }}要指向北方,您可以计算以度为单位的旋转:
float rotation = -azimut * 360 / (2 * 3.14159f); 总结 以上是内存溢出为你收集整理的如何在Android中获取方向(如北,西)全部内容,希望文章能够帮你解决如何在Android中获取方向(如北,西)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)