iPhone 中的 CLLocationManager 和航向度数

发布于 2024-08-17 07:28:36 字数 100 浏览 6 评论 0 原文

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

Using the CLLocationManager object's didUpdateHeading event, how do I convert the resulting heading.x and heading.y values into degrees I can plot onto an image of a compass?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

忆依然 2024-08-24 07:28:36

对于标题度,您可以使用 magicHeadingtrueHeading 属性而不是 x y。

真实标题

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

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

讨论

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

For headings degrees you can use magneticHeading and trueHeading properties instead of x and y.

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. A negative value indicates that the heading could not be determined.

盗心人 2024-08-24 07:28:36

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

This is how I rotated the uiimageview with the image of a compass. 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)];
        }
坐在坟头思考人生 2024-08-24 07:28:36

尝试:

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

   CLLocationDirection trueNorth = [newHeading trueHeading];

   CLLocationDirection magneticNorth = [newHeading magneticHeading];

}

CLLocationDirection 是 typedef double,因此您可以获得以度为单位的真实或磁航向。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文