title: Cannot get latitude and longtidute with CoreLocation in Objective-C
body: <p>I want to get the coordinates of the user, once user starts the app it should initialise GPS coordinates. I have followed this tutorial:
  <a href="http://www.iosdevnotes.com/2011/10/ios-corelocation-tutorial/" rel="nofollow">http://www.iosdevnotes.com/2011/10/ios-corelocation-tutorial/</a></p>
  
  <p>I have created a class named CurrentLocationWithGPS</p>
  
  <p>This is the header:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;CoreLocation/CoreLocation.h&gt;
  
  @interface CurrentLocationWithGPS : NSObject&lt;CLLocationManagerDelegate&gt;
  
  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation;
  
  - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error;
  
  - (void) getLocations;
  
  - (Float32) latitude;
  
  
  @property (strong, nonatomic) CLLocationManager *locationManager;
  @property (strong, nonatomic) CLLocation *currentLocation;
  
  @end
  </code></pre>
  
  <p>This is the implementation:</p>
  
  <pre><code>#import "CurrentLocationWithGPS.h"
  
  
  @implementation CurrentLocationWithGPS
  
  @synthesize locationManager, currentLocation;
  
  - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
      self.currentLocation = newLocation;
  
      if(newLocation.horizontalAccuracy &lt;= 100.0f) { [locationManager stopUpdatingLocation]; }
  }
  
  - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
      if(error.code == kCLErrorDenied) {
          [locationManager stopUpdatingLocation];
      } else if(error.code == kCLErrorLocationUnknown) {
          // retry
      } else {
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error retrieving location"
                                                          message:[error description]
                                                         delegate:nil
                                                cancelButtonTitle:@"OK"
                                                otherButtonTitles:nil];
          [alert show];
      }
  }
  
  
  - (void) getLocations {
      NSLog(@"GPS Location is initialising...");
  
      locationManager = [[CLLocationManager alloc] init];
      locationManager.delegate = self;
      [locationManager startUpdatingLocation];
      NSLog(@"GPS Location is initialised...");
  
  }
  
  - (Float32) latitude {
  
      return currentLocation.coordinate.latitude;
  }
  
  - (Float32) longitude {
  
      return currentLocation.coordinate.longitude;
  }
  
  @end
  </code></pre>
  
  <p>I call the getLocations function in a separate thread so that it wouldn't block anything else. Here is how I call it from another class:</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
  
      NSThread *myThread =[[NSThread alloc]initWithTarget:self selector:@selector(locationSet) object:nil];
      [myThread start];
  
  }
  
  - (void) locationSet {
  
      CurrentLocationWithGPS *locationFind = [[CurrentLocationWithGPS alloc] init];
      locationFind.getLocations;
      NSLog(@"latitude is %f", locationFind.latitude);
  }
  </code></pre>
  
  <p>Now the problem is both <code>latitude</code> and <code>longitdute</code> functions are returning 0.000, what am I missing here? I am developing for iOS6.1.</p>