我创建了一个应用程序,其中我想显示指南针。但我的应用程序显示空白页面..我还添加了CoreLocation框架..请帮我显示指南针。
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
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];
答案 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