gpt4 book ai didi

ios - CLLocationManager headingAvailable 返回 false

转载 作者:行者123 更新时间:2023-11-28 22:53:35 24 4
gpt4 key购买 nike

您好,我现在需要有关 iOS 中标题数据的帮助,我正在制作一个我在我的应用程序中使用的 CoreLocation 框架
我的.h文件

@interface ViewController : UIViewController<CLLocationManagerDelegate>{
UIImageView *arrowImage;
UILabel *magneticHeadingLabel;
UILabel *trueHeadingLabel;
CLLocationManager *locationManager;
}

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

在 .m 文件中

@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。这有点紧急,请帮助任何人

最佳答案

我不太确定,但据我所知,iPod touch 不包含 GPS/指南针模块。它通过 wifi 数据库获取其位置信息。因此,您不会获得标题,因为 iPod Touch 无法为您提供标题。

iPod Touch“只有”陀螺仪和加速度计可用。要读取有关这些的信息,您必须使用 Core Motion Framework

A CMMotionManager object is the gateway to the motion services provided by iOS. These services provide an application with accelerometer data, rotation-rate data, magnetometer data, and other device-motion data such as attitude. These types of data originate with a device’s accelerometers and (on some models) its magnetometer and gyroscope.

关于ios - CLLocationManager headingAvailable 返回 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11288469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com