2个GPS坐标之间的角度 [英] Angle between 2 GPS Coordinates
问题描述
我正在另一个使用AR的iPhone应用程序中工作,并且我正在创建自己的框架,但我无法获得与当前设备位置相关的第二个坐标的角度,任何人都知道一个好的资源,可以帮助我与此?
I'm working in another iPhone App that uses AR, and I'm creating my own framework, but I'm having trouble trying to get the angle of a second coordinate relative to the current device position, anyone know a good resource that could help me with this?
在此先感谢!
Thanks in advance!
推荐答案
如果两点相距足够近,且远离极点,则可以使用一些简单的触发:
If the two points are close enough together, and well away from the poles, you can use some simple trig:
float dy = lat2 - lat1;
float dx = cosf(M_PI/180*lat1)*(long2 - long1);
float angle = atan2f(dy, dx);
编辑:我忘了提及 latN
和 longN
- 因此 dx
和 dy
- 可以以度或弧度表示,只要不混合单位。然而, angle
总是会以弧度返回。当然,如果你乘以180 / M_PI,你可以恢复到原来的水平。
I forgot to mention that latN
and longN
— and therefore dx
and dy
— can be in degrees or radians, so long as you don't mix units. angle
, however, will always come back in radians. Of course, you can get it back to degrees if you multiply by 180/M_PI.
这篇关于2个GPS坐标之间的角度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!