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

  • Home
  • SEARCH
  • 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 9154857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:29:49+00:00 2026-06-17T12:29:49+00:00

I have two different UIViewControllers that need access to the user’s Latitude and Longitude

  • 0

I have two different UIViewControllers that need access to the user’s Latitude and Longitude. I only need to access the location once when the view appears. I am currently storing the LocationManager in the app delegate, but the viewDidAppear: method loads too quickly for the user’s location to be found. Does anyone know the best way to go about this? Thank you!

  • 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-06-17T12:29:50+00:00Added an answer on June 17, 2026 at 12:29 pm

    I create a shared LocationManager. Then startUpdatingLocation and stopUpdatingLocation after you get a callback.

    Here is the code I use:

    In your appDelegate add the following method:

    + (NHAppDelegate *)sharedDelegate
    {
        return (NHAppDelegate *)[[UIApplication sharedApplication] delegate];
    }
    

    And make the LocationManager available:

    @property (nonatomic, strong) CLLocationManager *locationManager;
    

    Then in your UIViewController you can do:

    [NHAppDelegate sharedDelegate].locationManager.delegate = self;
    [[NHAppDelegate sharedDelegate].locationManager startUpdatingLocation];
    

    Then I use the following code to get the location and display it in a UILabel.

    - (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
    {
        [self loadPositionWithLocation:newLocation];
    }
    
    - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
    {
        CLLocation *location = [locations objectAtIndex:0];
        [self loadPositionWithLocation:location];
    }
    
    -(void)loadPositionWithLocation:(CLLocation *)newLocation
    {
        CLGeocoder *geocoder = [[CLGeocoder alloc] init];
        [geocoder reverseGeocodeLocation:newLocation completionHandler:
         ^(NSArray* placemarks, NSError* error){
             if ([placemarks count] > 0)
             {
                 CLPlacemark *placemark = [placemarks objectAtIndex:0];
    
                 NSString *thoroughfare = placemark.thoroughfare;
                 NSString *subThoroughfare = placemark.subThoroughfare;
                 NSString *postalCode = placemark.postalCode;
                 NSString *locality = placemark.locality;
    
                 if( thoroughfare == nil )      {  thoroughfare = @"";     }
                 if( subThoroughfare == nil )   {  subThoroughfare = @"";  }
                 if( postalCode == nil )        {  postalCode = @"";       }
                 if( locality == nil )          {  locality = @"";         }
    
                 NSString *addressString = [NSString stringWithFormat:@"%@ %@\n%@ %@", thoroughfare, subThoroughfare, postalCode, locality];
    
                 self.positionLabel.text = addressString;
    
                 [[NHAppDelegate sharedDelegate].locationManager stopUpdatingLocation];
             }
         }];
    }
    

    Important is the last line stopUpdatingLocation so the LocationManager only gets called once.

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

Sidebar

Related Questions

I have two different modules that need access to a single file (One will
I have two different types of Sets that need to be iterated and one
I have two different tables from which I need to pull data blogs which
I have two different PHP files that both write to the same file. Each
I have two different kinds of objects that I'd like to live under the
I have two different installations on the same server that I plan to use
I have two different classes that share a common interface. Although the functionality is
I have two UIViewControllers which I sometimes need to show at the same time.
I have two different domains that both point to my homepage in the same
I have this iPad application with different NIBs and views. Each view has two

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.