简体   繁体   English

CLLocationManager和iPhone中的标题度

[英]CLLocationManager and degrees of heading in iPhone

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

For headings degrees you can use magneticHeading and trueHeading properties instead of x and y . 对于标题度,您可以使用magneticHeadingtrueHeading属性而不是xy

trueHeading trueHeading

The heading (measured in degrees) relative to true North. 相对于真北的航向(以度为单位)。 (read-only) (只读)

 @property(readonly, nonatomic) CLLocationDirection trueHeading 

Discussion 讨论

The value in this property represents the heading that points toward the geographic North Pole. 此属性中的值表示指向地理北极的标题。 The value in this property is always reported relative to the top of the device, regardless of the device's physical or interface orientation. 无论设备的物理或接口方向如何,此属性中的值始终相对于设备顶部报告。 The value 0 represents true North, 90 represents due East, 180 represents due South, and so on. 值0表示真北,90表示到期东,180表示到期南,依此类推。 A negative value indicates that the heading could not be determined. 负值表示无法确定标题。

This is how I rotated the uiimageview with the image of a compass. 这就是我用指南针的形象旋转uiimageview的方法。 The North needle was originally pointing upwards in the image. 北针最初指向图像中的向上。

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

Try: 尝试:

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

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection is typedef double and so you get the true or magnetic heading in degrees. CLLocationDirection是typedef double,因此您可以获得度数的真实或磁性标题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM