嗨,我遇到这种情况需要帮助才能在ios中标题数据,我正在我的应用程序中使用CoreLocation框架 我的.h文件
@interface ViewController : UIViewController<CLLocationManagerDelegate>{
UIImageView *arrowImage;
UILabel *magneticHeadingLabel;
UILabel *trueHeadingLabel;
CLLocationManager *locationManager;
}
@property (nonatomic, retain) CLLocationManager *locationManager;
@end
<。>文件中的
@implementation ViewController
@synthesize locationManager;
-(void)locationManager:(CLLocationManager*)manager didUpdateHeading:(CLHeading*)newHeading {
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
NSLog(@"=>%@",[NSString stringWithFormat:@"%.1fmi",newHeading.headingAccuracy]);
NSString *headingstring = [[NSString alloc] initWithFormat:@"%f",newHeading.trueHeading];
trueHeadingLabel.text = headingstring;
[headingstring release];
NSString *magneticstring = [[NSString alloc]initWithFormat:@"%f",newHeading.magneticHeading];
magneticHeadingLabel.text = magneticstring;
[magneticstring release];
}
-(void)getHeadInfo{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
self.locationManager.delegate = self;
if ([CLLocationManager headingAvailable] )
{
NSLog(@"Heading Available...!");
self.locationManager.headingFilter = kCLHeadingFilterNone;
[self.locationManager startUpdatingHeading];
}
else {
NSLog(@"No Heading Available: ");
UIAlertView *noCompassAlert = [[UIAlertView alloc] initWithTitle:@"No Compass!" message:@"This device does not have the ability to measure magnetic fields." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[noCompassAlert show];
[noCompassAlert release];
}
}
- (void)viewDidLoad {
[super viewDidLoad];
arrowImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"right_arrow"]];
arrowImage.frame = CGRectMake(95, 30, 128, 128);
[self.view addSubview:arrowImage];
trueHeadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 300, 250, 30)];
trueHeadingLabel.textAlignment = UITextAlignmentLeft;
trueHeadingLabel.textColor = [UIColor purpleColor];
trueHeadingLabel.backgroundColor = [UIColor clearColor];
trueHeadingLabel.font = [UIFont systemFontOfSize:13];
trueHeadingLabel.text = [NSString stringWithFormat:@"trueHeadingLabel:"];
[self.view addSubview:trueHeadingLabel];
magneticHeadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 350, 250, 30)];
magneticHeadingLabel.textAlignment = UITextAlignmentLeft;
magneticHeadingLabel.textColor = [UIColor purpleColor];
magneticHeadingLabel.backgroundColor = [UIColor clearColor];
magneticHeadingLabel.font = [UIFont systemFontOfSize:13];
magneticHeadingLabel.text = [NSString stringWithFormat:@"magneticHeadingLabel:"];
[self.view addSubview:magneticHeadingLabel];
UIButton *start = [[UIButton alloc]initWithFrame:CGRectMake(140, 310, 50, 30)];
[start setBackgroundColor:[UIColor redColor]];
[start setTitle:@"start" forState:UIControlStateNormal];
[start addTarget:self action:@selector(getHeadInfo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:start];
[start release];
}
事情是我知道模拟器没有返回标题数据,我正在使用ipod touch,但仍然[CLLocationManager headingAvailable]没有返回true.this有点紧急请帮助任何人
答案 0 :(得分:2)
我不太确定,但据我所知,iPod touch不包含GPS /指南针模块。它通过wifi数据库获取其位置信息。因此,你不会得到一个标题,因为iPod Touch无法提供给你。
iPod Touch“只有”陀螺仪和加速度计。要阅读有关这些的信息,您必须使用 Core Motion Framework
CMMotionManager对象是运动服务的网关 由iOS提供。这些服务提供了一个应用程序 加速度计数据,转速数据,磁力计数据等 设备运动数据,如态度。这些类型的数据来自 使用设备的加速度计和(在某些型号上)其磁力计 和陀螺仪。