首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >CLLocationManager headingAvailable返回false

CLLocationManager headingAvailable返回false
EN

Stack Overflow用户
提问于 2012-07-02 06:05:23
回答 1查看 1.3K关注 0票数 0

嗨,我在这里需要帮助,在ios中的数据标题,我正在做一个我使用的CoreLocation框架在我的应用程序

我的.h文件

代码语言:javascript
运行
复制
@interface ViewController : UIViewController<CLLocationManagerDelegate>{
    UIImageView *arrowImage; 
    UILabel *magneticHeadingLabel; 
    UILabel *trueHeadingLabel;
    CLLocationManager *locationManager;
}

@property (nonatomic, retain) CLLocationManager *locationManager;
@end

在.m文件中

代码语言:javascript
运行
复制
@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,但是CLLocationManager headingAvailable不返回true.this有点紧急--请帮助任何人

EN

Stack Overflow用户

发布于 2012-07-02 06:09:35

我不太确定,但据我所知,iPod触摸并不包括全球定位系统/指南针模块。它通过一个wifi数据库获取其位置信息。因此,您将不会得到一个标题,因为一个iPod触摸是不能给你的。

iPod触控“只有”一个陀螺仪和一个加速度计可用。要读取有关这些的信息,您必须使用核心运动框架

CMMotionManager对象是iOS提供的运动服务的网关。这些服务提供了加速度计数据、旋转速率数据、磁强计数据和其他设备运动数据(如姿态)的应用程序。这些类型的数据来源于设备的加速度计和(在某些型号上)磁强计和陀螺仪。

票数 2
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11288469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档