在iPad上制作罗盘应用程序

时间:2011-05-16 06:24:03

标签: 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];
    }
}

请帮帮我

Sreekumar Kalarikkal 印度

2 个答案:

答案 0 :(得分:6)

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

在设备上,此代码运行正常。

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

答案 1 :(得分:1)

Crystal ball表示你缺少接口标题中的协议:@interface xxxx : xxx <CLLocationManagerDelegate>