CLLocationManager和iPhone中的标题度

时间:2010-01-11 17:48:02

标签: iphone cllocationmanager degrees

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

3 个答案:

答案 0 :(得分:3)

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

  

<强> trueHeading

     

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

@property(readonly, nonatomic) CLLocationDirection trueHeading
     

讨论

     

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

答案 1 :(得分:1)

尝试:

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

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection是typedef double,因此您可以获得真实或磁性标题。

答案 2 :(得分:1)

这就是我用指南针的形象旋转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)];
        }
相关问题