Take the tour ×

This is the code that I have in my AppDelegate Class


    CLLocationManager *locationManager = [[CLLocationManager alloc] init];
    locationManager.delegate = self;
    locationManager.distanceFilter = 1000;  // 1 Km
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
    [locationManager startUpdatingLocation];

And this is the delegate method i have in my AppDelegate Class

    //This is the delegate method for CoreLocation
- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

        //printf("AppDelegate latitude %+.6f, longitude %+.6f\n", newLocation.coordinate.latitude, newLocation.coordinate.longitude);


Its working in 3.0, 3.1, 3.1.3 , but its not working in 4.0 simulator and device both.

What is the reason ?

share|improve this question
Thanks @Scott Christopherson for some positive approach..... but still we have become puppets and have to change our code every time there is a new iPhone SDK release .Always find some methods are deprecated or not working.... –  Biranchi Jun 17 '10 at 5:07
Thanks @Scott Christopherson please vote to close this Question .... as no one can solve this issue... –  Biranchi Jun 17 '10 at 5:08
Facing same problem here, are you sure it takes about 40s to update location? –  Prashant Jul 8 '10 at 6:03
Did anyone find a solution for this??? –  Urs Jan 27 '11 at 15:36
Its working on the Device iOS4.0 but with 40 seconds delay , while its taking 2/3 seconds on iPhone OS 3.1.2 –  Biranchi Jan 27 '11 at 15:36
add comment

4 Answers

up vote 9 down vote accepted

I had a similar error, and is solved now. The issue is declaring locationManager variable locally. Declare it instead as a class variable and make sure it is retained either directly or via property retain (or strong if you use ARC). That solves the problem! The issue was de locationManager variable was released and never updated the delegate. Here the code:

.h file:

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

@interface MapViewController : UIViewController <MKMapViewDelegate, CLLocationManagerDelegate> {
    MKMapView *_mapView;
    CLLocationManager *_locationManager;

@property(nonatomic, strong) CLLocationManager *locationManager;


.m file:

self.locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[_locationManager startUpdatingLocation];

I hope it helps.

share|improve this answer
add comment

Put the codes in a viewController "which is pushed to navigationController".

My code is.

In SomeViewController.h

#import <MapKit/MapKit.h>
@interface SomeViewController : UIViewController<CLLocationManagerDelegate>{
@property (nonatomic, strong) CLLocationManager *locationManager;

In SomeViewController.m

#import "SomeViewController.h"

@implementation SomeViewController

    if ([CLLocationManager locationServicesEnabled]) {
        if (!self.locationManager) {
            self.locationManager = [[CLLocationManager alloc] init];
            self.locationManager.delegate = self;
            self.locationManager.distanceFilter = kCLDistanceFilterNone;
            self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
            [self.locationManager startUpdatingLocation];

    CLLocation *lo = [locations objectAtIndex:0];
    NSLog(@"latitude = %f, longitude = %f", lo.coordinate.latitude, lo.coordinate.longitude);

    [manager stopUpdatingHeading];
    [manager stopUpdatingLocation];

The problem I think is because of ARC, locationManager is released.

share|improve this answer
add comment

Does -locationManager:didFailWithError: in your delegate ever get called? I'm just thinking, maybe you denied access to location data at some point and now don't get prompted, but access is denied.

share|improve this answer
add comment

Are you sure you are not deallocating the location manager somewhere? The code you have shows it being allocated in the didFinishLaunching... method but then being forgotten about (though it's still retained and so should still work).

Do you even see that initial popup asking you if it's OK to get the user location?

share|improve this answer
yes tried every possible solution.... do i need to reinstall the iphone SDK ???? –  Biranchi Jun 17 '10 at 5:09
add comment

Your Answer


