Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4084418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:26:14+00:00 2026-05-20T18:26:14+00:00

Hey guys, I am trying to build an app that will use a compass

  • 0

Hey guys, I am trying to build an app that will use a compass to point in the direction of a predetermined location, but for now I am trying to understand just how to make a basic compass. I followed a guide, however I am always get “-1” as the header, and have only gotten it to work once, and I haven’t changed code since. Any ideas would be helpful.

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface TrackerViewController : UIViewController <CLLocationManagerDelegate> {

}

@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, retain) IBOutlet UISwitch *toggle;
@property (nonatomic, retain) IBOutlet UIImageView *compass;
@property (nonatomic, retain) IBOutlet UILabel *headingLabel;

-(IBAction)toggleSwitch;

@end

and the implementation file…

#import "TrackerViewController.h"


@implementation TrackerViewController

@synthesize locationManager; 
@synthesize toggle; 
@synthesize compass; 
@synthesize headingLabel;

- (IBAction)toggleSwitch {
if(self.toggle.isOn) {
    [self.locationManager startUpdatingHeading];
} else {
    [self.locationManager stopUpdatingHeading];
}
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];

if ([CLLocationManager headingAvailable]) {
    self.locationManager = [[[CLLocationManager alloc] init] autorelease]; 
    self.locationManager.delegate = self;
} else {
    [[[[UIAlertView alloc] initWithTitle:@"Aw snap!" 
                                 message:@"Device doesn't support heading updates" 
                                delegate:nil 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil] autorelease] show];   
}
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading 
*)newHeading {
float heading = [newHeading trueHeading] * M_PI / 180.0;
self.compass.transform = CGAffineTransformMakeRotation(-heading);
self.headingLabel.text = [NSString stringWithFormat:@"%d°", (int)[newHeading trueHeading]];
NSLog(@"%d", (int)[newHeading trueHeading]);
}


- (void)locationManager:(CLLocationManager *)manager 
   didFailWithError:(NSError *)error {

//  NSLog(@"Error!");

if (error.code == kCLErrorDenied) {
    [[[[UIAlertView alloc] initWithTitle:@"Aw snap!" 
                                 message:@"User didn't allow heading updates" 
                                delegate:nil 
                       cancelButtonTitle:@"OK" 
                       otherButtonTitles:nil] autorelease] show];
    self.toggle.on = NO;
    [self.locationManager stopUpdatingHeading];
}
}


- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
self.locationManager = nil;
self.compass = nil;
self.toggle = nil;
self.headingLabel = nil;
[super dealloc];
}

@end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T18:26:14+00:00Added an answer on May 20, 2026 at 6:26 pm

    magneticHeading
    The value in this property represents the heading relative to the magnetic North Pole, which is different from the geographic North Pole. The value 0 means the device is pointed toward magnetic north, 90 means it is pointed east, 180 means it is pointed south, and so on. The value in this property should always be valid.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys i'm trying to build a little app that pulls in the users
Hey guys I am trying to build a database that maps NSStrings to int.
Hey guys, I've been trying to build something simple in Flash 8, and I
hey guys im trying to save a url link in a html form but
Hey guys I am having trouble trying to convert my web app to support
Hey guys I'm trying to work my way through this but am having an
Hey guys I'm trying to make a basic calculator (polish style) but can't figure
Hey Guys I Am Trying To Use One Regex Pattern If And Else //$pattern
Hey guys i am trying to install the dropbox-api onto my suse 11.4 but
Hey guys, I'm trying to make a small addition to a web app I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.