显示特定位置的 iPhone 罗盘

标签 iphone objective-c xcode compass-geolocation direction

我是 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));
}

计算方位的好链接:

关于显示特定位置的 iPhone 罗盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7298193/

相关文章:

iPhone,我可以在没有 iPhone 4 的情况下创建视网膜质量的屏幕截图吗?也许是模拟器?

ios - 应用程序显示拉伸(stretch)键盘

iphone - 如何在 iOS 应用程序运行时提取有关 UI 元素的信息?

objective-c - 进入编辑模式时保持 UITableViewCell 背景颜色

ios - 如何在导航 Controller 模式对话框 View 中触发后退按钮

c# - 在 C# 中获取连接的设备序列号

objective-c - 同步返回 objective-c

swift - 如何使用 alamofire 将服务的响应存储在模型中

c - C 和 Objective-C 入门

ios - ImagePicker 选取图像后 CollectionView 图像不更新