Adr*_*rro 8 android latitude-longitude augmented-reality
我有一个增强现实的应用程序,我已经存储了相应的纬度和经度,如地铁,加油站,名胜古迹等信息.
现在,根据设备的方向,我会在设备的摄像机视图中显示每个站点的标记.与Layar和Wikitude相似.
它需要三天不停地搜索,并没有找到任何人解释如何解决这个问题.
由于关于这个主题的信息非常少,而且我最近在iPhone上解决了这个问题,我想我会分享我的方法给任何可以使它与Android一起工作的人(除了数学函数之外,在这个答案中除了iPhone之外什么都没有. sin,cos和fmod,可以在java.lang.Math中找到.这些是我采取的步骤:
计算相对于北方的lat2/lon2的角度.这也在上面的链接中描述,但我有一点点麻烦让这个工作,这里是C代码:
double latDelta = (lat2 - lat1);
double lonDelta = (lon2 - lon1);
double y = sin(lonDelta) * cos(lat2);
double x = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2)* cos(lonDelta);
double angle = atan2(y, x); //not finished here yet
double headingDeg = compass.currentHeading;
double angleDeg = angle * 180/PI;
double heading = headingDeg*PI/180;
angle = fmod(angleDeg + 360, 360) * PI/180; //normalize to 0 to 360 (instead of -180 to 180), then convert back to radians
angleDeg = angle * 180/PI;
使用标准三角学,我计算x和y.请记住,这些坐标是在3D空间中,所以我们还没有完成,因为你仍然需要将它们映射到2D:
x = sin(angle-heading) * distance;
z = cos(angle-heading) * distance; //typically, z faces into the screen, but in our 2D map, it is a y-coordinate, as if you are looking from the bottom down on the world, like Google Maps
最后,使用投影公式,您可以计算屏幕x(我没有做y因为我的项目不需要,但您需要获取加速器数据并确定设备是否垂直于地面).投影公式可在此处找到(滚动到最底部):http://membres.multimania.fr/amycoders/tutorials/3dbasics.html
double screenX = (x * 256) / z
现在,您可以使用此x坐标在屏幕上移动图像或标记.记住几点:
(出于某种原因,我无法在此计算机上正确格式化代码,因此如果有人想编辑此答案,请随意).
| 归档时间: |
|
| 查看次数: |
5306 次 |
| 最近记录: |