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

有帮助吗?

解决方案

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

真标题

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

@property(readonly, nonatomic) CLLocationDirection trueHeading

讨论

该属性中的值表示指向地理北极的航向。无论设备的物理或界面方向如何,此属性中的值始终相对于设备顶部报告。值 0 代表正北,90 代表正东,180 代表正南,依此类推。负值表示无法确定航向。

其他提示

这是我如何旋转的UIImageView与罗盘的图像。北针最初的图像中指向上方。

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)];
        }

尝试:

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection是双重的typedef,所以你获得学位的真或磁航向。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top