首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iPhone中的CLLocationManager和航向度数

iPhone中的CLLocationManager和航向度数
EN

Stack Overflow用户
提问于 2010-01-12 01:48:02
回答 3查看 8.5K关注 0票数 3

使用CLLocationManager对象的didUpdateHeading事件,如何将生成的heading.x和heading.y值转换为可以在指南针图像上绘制的度数?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-01-12 01:50:16

对于标题度,您可以使用magneticHeadingtrueHeading属性,而不是xy

trueHeading

相对于正北的航向(以度为单位)。(只读)

@property(只读,非原子) CLLocationDirection trueHeading

讨论

此属性中的值表示指向地理北极的方向。此属性中的值始终相对于设备顶部报告,而与设备的物理或接口方向无关。值0表示正北,90表示正东,180表示正南,依此类推。负值表示无法确定标题。

票数 3
EN

Stack Overflow用户

发布于 2010-01-12 01:56:05

尝试:

代码语言:javascript
运行
复制
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection是类型定义的双精度,所以你可以得到真的或磁性的方向。

票数 1
EN

Stack Overflow用户

发布于 2012-05-12 17:46:34

这就是我用指南针的图像旋转uiimageview的方式。在图像中,北针最初指向上方。

代码语言:javascript
运行
复制
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
            NSLog(@"UIInterfaceOrientationLandscapeLeft");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading - 90) *3.14/180)*-1) )];

        }else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight){
            NSLog(@"UIInterfaceOrientationLandscapeRight");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 90) *3.14/180)*-1))];

        }else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
            NSLog(@"UIInterfaceOrientationPortraitUpsideDown");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((((newHeading.magneticHeading + 180) *3.14/180)*-1) )];

        }else{
            NSLog(@"Portrait");
            [self.compassImageViewIphone setTransform:CGAffineTransformMakeRotation((newHeading.magneticHeading *3.14/180)*-1)];
        }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2043685

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档