指南针未显示在iphone中

时间:2012-04-10 06:09:03

标签: iphone ipad

我创建了一个应用程序,其中我想显示指南针。但我的应用程序显示空白页面..我还添加了CoreLocation框架..请帮我显示指南针。

.h文件代码:

import "UIKit/UIKit.h"
import "CoreLocation/CoreLocation.h"

@interface Compass_VIew : UIViewController<CLLocationManagerDelegate> 
    {

IBOutlet UIImageView *arrow;

 IBOutlet UIImageView *arrowC;

 CLLocationManager *locManager;

}

@property (nonatomic, retain) CLLocationManager *locManager;

@property(readonly, nonatomic) BOOL headingAvailable;

@end

.m文件代码

didUpdateHeading方法代码:

NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);

viewDidLoad方法代码:

[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
[[self navigationController] setNavigationBarHidden:NO animated:NO];
locManager = [[[CLLocationManager alloc] init] autorelease];
locManager.desiredAccuracy= kCLLocationAccuracyBest;
locManager.delegate = self;
[self.locManager startUpdatingHeading];

1 个答案:

答案 0 :(得分:2)

你需要为指南针指针进行转换

应该是这样的

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor clearColor];

    locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    locationManager.distanceFilter = kCLDistanceFilterNone; 
    [locationManager startUpdatingLocation];
    [locationManager startUpdatingHeading];

    CLLocation *location = [locationManager location];
    CLLocationCoordinate2D user = [location coordinate];


}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
    CLLocationCoordinate2D here =  newLocation.coordinate;


}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading {

    double trueheading = newHeading.magneticHeading;
    double northangle = (trueheading*M_PI/180);
    redPin.transform = CGAffineTransformMakeRotation(northangle); 
}

这里redPin是我的针视图,顺便说一句,别忘了导入CoreLocation Framework