使用CLLocationManager对象的didUpdateHeading事件,如何将生成的heading.x和heading.y值转换为可以在指南针图像上绘制的度数?
发布于 2010-01-12 01:50:16
对于标题度,您可以使用magneticHeading和trueHeading属性,而不是x和y。
trueHeading
相对于正北的航向(以度为单位)。(只读)
@property(只读,非原子) CLLocationDirection trueHeading
讨论
此属性中的值表示指向地理北极的方向。此属性中的值始终相对于设备顶部报告,而与设备的物理或接口方向无关。值0表示正北,90表示正东,180表示正南,依此类推。负值表示无法确定标题。
发布于 2010-01-12 01:56:05
尝试:
- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {
CLLocationDirection trueNorth = [newHeading trueHeading];
CLLocationDirection magneticNorth = [newHeading magneticHeading];
}CLLocationDirection是类型定义的双精度,所以你可以得到真的或磁性的方向。
发布于 2012-05-12 17:46:34
这就是我用指南针的图像旋转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)];
}https://stackoverflow.com/questions/2043685
复制相似问题