本文介绍了安卓:有没有办法从Location.getAltitude一边得到高度()? (我用传感器听说过)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法从Location.getAltitude一边得到高度()?我听说使用传感器,但没有思想,不能找到网。
Is there a way to obtain altitude aside from Location.getAltitude()?I've heard using Sensor but don't have idea and can't find on net.
UPDATES1 我发现 SensorManager.getAltitude(浮动,浮动)
使用API 9级了,但没有想法就如何落实它。你会与我们分享。
UPDATES1I found SensorManager.getAltitude(float, float)
using API Level 9 up but don't have idea on how to implement it. Would you share with us.
推荐答案
我知道它的晚,但任何人都在寻找它,这可能有助于
I know it's late but for anyone looking for it, that might help
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
public class MyActivity extends Activity implements SensorEventListener {
private SensorManager sensorManager;
private Sensor sensor;
private float altitude = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
sensor = sensorManager.getDefaultSensor(Sensor.TYPE_PRESSURE);
}
@Override
protected void onResume() {
super.onResume();
if (sensor != null)
sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
@Override
protected void onPause() {
super.onPause();
sensorManager.unregisterListener(this);
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged(SensorEvent event) {
float presure = event.values[0];
altitude = SensorManager.getAltitude(SensorManager.PRESSURE_STANDARD_ATMOSPHERE, presure);
System.out.println("altitude => " + altitude);
}
}
这篇关于安卓:有没有办法从Location.getAltitude一边得到高度()? (我用传感器听说过)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!