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 6637133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:16:32+00:00 2026-05-25T23:16:32+00:00

I downloaded the source code of this tutorial and played a bit with it.

  • 0

I downloaded the source code of this tutorial and played a bit with it.
All working fine.

Now I wanted to create my own project to implement location and heading. But after writing all, it does not work. I don’t even see a GPS indication on the top.

When I run the other app, its al fine.
Xcode does not give any errors or warnings.

my code:
(it did not change anything in the AppDelegate).

LocationAndHeadingTestViewController.h

#import <UIKit/UIKit.h>
#import "LocationController.h"

@interface LocationAndHeadingTestViewController : UIViewController <LocationControllerDelegate>
{
    LocationController *_locationController;

    IBOutlet UILabel *_errorLabel;

    //Location
    IBOutlet UILabel *_locationTimeLabel;
    IBOutlet UILabel *_latitudeLabel;
    IBOutlet UILabel *_longitudeLabel;
    IBOutlet UILabel *_altitudeLabel;

    //Heading
    IBOutlet UILabel *_headingTimeLabel;
    IBOutlet UILabel *_trueHeadingLabel;
    IBOutlet UILabel *_magneticHeadingLabel;
    IBOutlet UILabel *_headingAccuracyLabel;

    IBOutlet UIImageView *_compass;
}

@property (nonatomic, retain) LocationController *locationController;

@end

LocationAndHeadingTestViewController.m

#import "LocationAndHeadingTestViewController.h"

@implementation LocationAndHeadingTestViewController

@synthesize locationController = _locationController;

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    _locationController = [LocationController new];
    _locationController.delegate = self;
    [_locationController.locationManager startUpdatingLocation];
    [_locationController.locationManager startUpdatingHeading];
}


- (void)locationUpdate:(CLLocation *)location 
{
    [_locationTimeLabel setText:[NSString stringWithFormat:@"%@", location.timestamp]];
    [_latitudeLabel setText:[NSString stringWithFormat:@"%f", location.coordinate.latitude]];
    [_longitudeLabel setText:[NSString stringWithFormat:@"%f", location.coordinate.longitude]];
    [_altitudeLabel setText:[NSString stringWithFormat:@"%f", [location altitude]]];
}

- (void)headingUpdate:(CLHeading *)heading
{
    [_headingTimeLabel setText:[NSString stringWithFormat:@"%@", heading.timestamp]];
    [_trueHeadingLabel setText:[NSString stringWithFormat:@"%f", heading.trueHeading]];
    [_magneticHeadingLabel setText:[NSString stringWithFormat:@"%f", heading.magneticHeading]];
    [_headingAccuracyLabel setText:[NSString stringWithFormat:@"%f", heading.headingAccuracy]];
}

- (void)locationError:(NSError *)error 
{
    _errorLabel.text = [error description];
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)viewDidUnload 
{
    [super viewDidUnload];
}

- (void)dealloc 
{
    [_locationController release];
    [super dealloc];
}

@end

LocationController.h

#import <CoreLocation/CoreLocation.h>

@protocol LocationControllerDelegate
@required

- (void)locationUpdate:(CLLocation *)location;
- (void)headingUpdate:(CLHeading *)heading;
- (void)locationError:(NSError *)error;

@end

@interface LocationController : NSObject <CLLocationManagerDelegate>
{
    CLLocationManager *_locationManager;
    id _delegate;
}

@property (nonatomic, retain) CLLocationManager *locationManager;
@property (nonatomic, assign) id delegate;

@end

LocationController.m

#import <CoreLocation/CoreLocation.h>
#import "LocationController.h"

@implementation LocationController

@synthesize locationManager = _locationManager, delegate = _delegate;

- (id)init
{
    if(self = [super init]) 
    {
        _locationManager = [[CLLocationManager new] autorelease];
        _locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        _locationManager.delegate = self;
    }

    return self;
}

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation 
{
    if([self.delegate conformsToProtocol:@protocol(LocationControllerDelegate)]) 
    {
        [self.delegate locationUpdate:newLocation];
    }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error 
{
    if([self.delegate conformsToProtocol:@protocol(LocationControllerDelegate)]) 
    {
        [_delegate locationError:error];
    }
}

- (void)locationManager:(CLLocationManager *)manager didUpdateHeading:(CLHeading *)newHeading
{
    if([self.delegate conformsToProtocol:@protocol(LocationControllerDelegate)]) 
    {
        [_delegate headingUpdate:newHeading];
    }
}

- (void)dealloc 
{
    [_locationManager release];
    [super dealloc];
}

@end

It is fairly simple but I think I really overlook something.

Ps. I will change the id delegate to id <..> delegate

  • 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-25T23:16:33+00:00Added an answer on May 25, 2026 at 11:16 pm

    You shouldn’t be autoreleasing the CLLocationManager object:

    _locationManager = [[CLLocationManager new] autorelease];
    

    That’s a “retain” property. You need to remove the autorelease, you are going to release it in the dealloc. You can only release it once.

    If you had assigned it using the setter, then the setter would have retained it for you. Like this would be OK:

    self.locationManager = [[CLLocationManager new] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I downloaded the source code from this tutorial after a failed attempt to make
I downloaded the source code to this project: SilverVNC - a VNC Viewer with
So I'm working through the code in this tutorial which has a small button
This is something I've really never seen but, I downloaded the source code of
I downloaded the source code and wanted to compile the file of scanner. It
I followed this tutorial and the source code : http://blog.objectgraph.com/index.php/2010/04/20/encrypting-decrypting-base64-encode-decode-in-iphone-objective-c/ And then, I downloaded
I downloaded the qt embedded demo source code recently on my linux machine. Following
I am using svn to download the source code to an open source project.
I downloaded a WPFToolkit source, because I wanted to override the default generic template
Ok so I've downloaded an open source project that I'm looking at customising for

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.