在iPad上制作指南针应用程序 [英] make a compass application in iPad

查看:114
本文介绍了在iPad上制作指南针应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to make a compass application that will specify the geographic directions(north, east, west, south),

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

So i used CoreLocation framework in my application. I found in many forums that when this function [locationManager startUpdatingHeading]; calls it will automatically call the function: -(void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading

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

But in my application the second function is not automatically invoked, so i cant able to make my application, Please help me....... My code is given bellow:

-(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
印度

please help me

Sreekumar Kalarikkal India

推荐答案

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

There is just no heading available on the iOS simulator (and your code is giving the appropriate alert view).

在设备上,此代码工作正常。

On the device, this code just works fine.

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

(Tested your code both on simulator and device)

这篇关于在iPad上制作指南针应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆