【发布时间】:2010-01-11 17:48:01
【问题描述】:
使用 CLLocationManager 对象的 didUpdateHeading 事件,如何将生成的 heading.x 和 heading.y 值转换为可以绘制到指南针图像上的度数?
【问题讨论】:
标签: iphone cllocationmanager degrees
使用 CLLocationManager 对象的 didUpdateHeading 事件,如何将生成的 heading.x 和 heading.y 值转换为可以绘制到指南针图像上的度数?
【问题讨论】:
标签: iphone cllocationmanager degrees
对于航向度数,您可以使用magneticHeading 和trueHeading 属性而不是x 和y。
真标题
相对于真北的航向(以度为单位)。 (只读)
@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 double 类型,因此您可以得到以度数为单位的真航向或磁航向。
【讨论】: