我是 Objective-c 的新手,所以如果我的问题太垃圾,我想道歉。
我正在编写一个指南针,但它正在工作(感谢教程)。
给出了实际位置(经度和纬度)。
指南针内的箭头是否有可能向我显示到特定位置(经度2和纬度2)的方向?
我读到我必须考虑 iPhone 的磁性和真实航向。
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
double heading = newHeading.trueHeading; //in degree relative to true north
double bearing = ... //get current bearing in degree relative to true north
//with the JS library mentioned below it would be something like
//bearing = userLoc.bearingTo(destionation);
//just two lines, the the sake of the example
double rotationInDegree = (bearing - heading); //the important line
rotationInDegree = fmod((rotationInDegree + 360), 360); //just to be on the safe side :-)
compassViewPerhapsAsImage.transform=CGAffineTransformMakeRotation(DegreesToRadians(rotationInDegree));
}
计算轴承的良好链接:
-
http://www.movable-type.co.uk/scripts/latlong.html http://www.movable-type.co.uk/scripts/latlong.html有解释和 Javascript 示例,但很容易转换! :-)
-
https://github.com/tadelv/CLLocation-Bearing https://github.com/tadelv/CLLocation-Bearing作为 Objective C 项目
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)