通过增强现实找到餐馆和旅游景点
在我的应用程序中,我想使用增强现实来查找家庭餐馆等地方。 我想要做的是,当我启动应用程序时,相机打开,然后我想找到相机方向的位置。例如,我启动应用程序,我面向东,手机键盘面向我,即西,然后是东方向的地方。 我已经编写了一些启动相机的代码,请建议任何可用于此任务的 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();
}
}
}
in my app i want to use augmented reality to find places like family restaurants etc..
What i want to do is that when i start my app camera turned on and then i want to locate the places in the direction of the camera .for example i start the app and i m facing the east and phone keypad is facing towards me i.e west,then the places which are in east direction.
i have written some code which starts the camera, please suggest any api available for this task and example and tutorial to do that .thanks in advance.
here is my code.
@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();
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
共有三个步骤。
1) 使用传感器确定您的位置和方向。
2)通过使用例如大圆距离和方位确定已知GPS坐标的相对位置和方位,从GPS坐标空间转换到平面坐标空间。 http://www.yourhomenow.com/house/havesine.html(您的设备保持使用此方案在坐标空间的原点)
3)进行透视投影 http://en.wikipedia.org/wiki/3D_projection#Perspective_projection 来确定物体应该出现在你的显示器(好吧,你的相机传感器)平面上的哪个位置,所以你可以增强它们。
首先,您可以简化情况,使手机仅保持在一个方向,并且您无需更新显示以考虑从屏幕到相机定义的轴的方向,因为对于基本的“查找器”应用程序,大多数人不会绕该轴旋转。注意万向节锁 http://en.wikipedia.org/wiki/Gimbal_lock - 我'我不确定 Android 传感器 API 是否会为您解决这个问题。
There are three steps.
1) Determine your position and orientation using sensors.
2) Convert from GPS coordinate space to a planar coordinate space by determining the relative position and bearing of known GPS coordinates using e.g great circle distance and bearing. http://www.yourhomenow.com/house/haversine.html (your devices stays at the origin of the coordinate space with this scheme)
3) Do a perspective projection http://en.wikipedia.org/wiki/3D_projection#Perspective_projection to figure out where on the plane that is your display (ok, your camera sensor) the objects should appear, so you can augment them.
To start with, you can simplify the situation so the phone is only held in one orientation, and you don't update the display to account for orientation about the axis defined from the screen to the camera, since for a basic "finder" app, most people won't rotate in that axis. Be aware of gimbal lock http://en.wikipedia.org/wiki/Gimbal_lock - I'm not sure if the Android sensor APIs take care of that for you.
这是重要的链接。
http://code.google.com/apis/maps/documentation/places/
现在我需要做的就是解析 xml 文件并获取位置..
Here is the important link.
http://code.google.com/apis/maps/documentation/places/
now all i need to do is the parse the xml file and get the places..