【问题标题】:CLLocationManager and degrees of heading in iPhoneCLLocationManager 和 iPhone 中的航向度数
【发布时间】:2010-01-11 17:48:01
【问题描述】:

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

【问题讨论】:

    标签: iphone cllocationmanager degrees


    【解决方案1】:

    对于航向度数,您可以使用magneticHeadingtrueHeading 属性而不是xy

    真标题

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

    @property(readonly, nonatomic) CLLocationDirection trueHeading
    

    讨论

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

    【讨论】:

      【解决方案2】:

      这就是我使用指南针图像旋转 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)];
              }
      

      【讨论】:

        【解决方案3】:

        试试:

        - (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
        
           CLLocationDirection trueNorth = [newHeading trueHeading];
        
           CLLocationDirection magneticNorth = [newHeading magneticHeading];
        
        }
        

        CLLocationDirection 是 typedef double 类型,因此您可以得到以度数为单位的真航向或磁航向。

        【讨论】:

        • true 不是有效的变量名。
        猜你喜欢
        • 2015-02-09
        • 1970-01-01
        • 2014-03-11
        • 2011-10-18
        • 2012-03-24
        • 1970-01-01
        • 2012-02-22
        • 2013-09-24
        • 1970-01-01
        相关资源
        最近更新 更多