My purpose is to get the longitude/latitude of the user when the view is loaded and to store the values in two variables for later calculations. I don\'t need to track the u
As soon as you call [locationManager startUpdatingLocation];
your viewDidLoad method is done. You need to implement
-(void) locationManager: (CLLocationManager *)manager didUpdateToLocation: (CLLocation *) newLocation
fromLocation: (CLLocation *) oldLocation
and
- (void) locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
which will be called by your locationManager when it gets the location, or when it fails. In both of those methods, you can call [locationManager stopUpdatingLocation]
.
Inside the didUpdateToLocation method, you should move all your code from viewDidLoad, starting with CLLocation *location = [locationManager location];
That's where you'll get proper values.