在我的应用程序中,我想使用增强现实来查找家庭餐馆等地方。我想做的是,当我启动我的应用程序时打开相机,然后我想在相机的方向上定位这些地方。例如我启动应用程序,我面向东方,手机键盘面向我,即西方,然后是东方的地方。我已经编写了一些启动相机的代码,请建议任何可用于此任务的 api 以及示例和教程来做到这一点。提前谢谢。这是我的代码。
@Override
public void onCreate(Bundle savedInstanceState) {
// try{
super.onCreate(savedInstanceState);
sensorMan = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
sensorMan.registerListener(this,sensorMan.getDefaultSensor(SensorManager.SENSOR_ORIENTATION),
SensorManager.SENSOR_DELAY_FASTEST);
//lastUpdate = System.currentTimeMillis();
sensorMan.registerListener(this, sensorMan.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}//end of oncreate
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// TODO Auto-generated method stub
}
@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
Toast.makeText(this, "X-rawDirection->"+event.values[0], Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Y-rawDirection->"+event.values[1], Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Z-rawDirection->"+event.values[2], Toast.LENGTH_SHORT).show();
}
if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {
Toast.makeText(this, "X-rawDirection TYPE_ORIENTATION->"+event.values[0], Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Y-rawDirection TYPE_ORIENTATION->"+event.values[1], Toast.LENGTH_SHORT).show();
Toast.makeText(this, "Z-rawDirection TYPE_ORIENTATION->"+event.values[2], Toast.LENGTH_SHORT).show();
}
}
}