Reputation: 739
I have created one application in which i want to display compass.but my application is showing me blank page..I have added CoreLocation framework also..Please help me to display compass.
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 method code:
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
viewDidLoad method code:
[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];
Upvotes: 1
Views: 225
Reputation: 4946
you need to give the transform for the needle of the compass
it should be like this
- (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);
}
Here redPin is my needle view and by the way dont forget to import CoreLocation Framework
Upvotes: 2