在iPad上制作罗盘应用程序

Sre*_*kal 2 iphone ipad

我想制作一个指南针应用程序,指定地理方向(北,东,西,南),

所以我在我的应用程序中使用了CoreLocation框架.我在很多论坛中发现,当这个函数[locationManager startUpdatingHeading];调用它时会自动调用该函数:-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

但在我的应用程序中第二个函数不会自动调用,所以我无法使我的应用程序,请帮助我.......我的代码如下:

-(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
    NSLog(@"New true heading: %f", newHeading.trueHeading);
    NSString *headingstring = [[NSString alloc] initWithFormat:@"%f",newHeading.trueHeading];
    trueHeading.text = headingstring;
    [headingstring release];

    NSString *magneticstring = [[NSString alloc] initWithFormat:@"%f",newHeading.magneticHeading];
    magneticHeading.text = magneticstring;
    [magneticstring release];
}

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    [super viewDidLoad];

    locationManager=[[CLLocationManager alloc] init];
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;
    locationManager.delegate=self;
    //Start the compass updates.
    if (CLLocationManager.headingAvailable ) {     
        [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];
    }
}
Run Code Online (Sandbox Code Playgroud)

请帮我

Sreekumar Kalarikkal印度

Eik*_*iko 6

iOS模拟器上没有可用的标题(并且您的代码提供了适当的警报视图).

在设备上,这段代码运行正常.

(在模拟器和设备上测试了您的代码)