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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:58:31+00:00 2026-06-10T20:58:31+00:00

I am trying to get the current location whenever required and stop updating locations

  • 0

I am trying to get the current location whenever required and stop updating locations immediately. For this I wrote following code but continuos waiting on volatile flag doen’t seem to working. It doesn’t fire location updates evens when I am waiting on the flag. Could someone please tell me what’s wrong in my code. Thanks.

CurrentLocation.h file:

@property (nonatomic, assign) volatile BOOL locationUpdatedFlag;
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLLocation *currentLocation;

CurrentLocation.m file:

@synthesize currentLocation = _currentLocation;
@synthesize locationManager = _locationManager;
@synthesize locationUpdatedFlag = _locationUpdatedFlag;

- (void)xxx
{
    self.locationManager = [[CLLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters;
    [self.locationManager startUpdatingLocation];

    self.locationUpdatedFlag = NO;

    while(!self.locationUpdatedFlag)
        [NSThread sleepForTimeInterval:.1];

    // Use self.currentLocation

}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
    self.currentLocation = newLocation;
    self.locationUpdatedFlag = YES;
    [manager stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{   
    NSLog(@"Error from Location Manager");
    self.locationUpdatedFlag = YES;
}
  • 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-10T20:58:33+00:00Added an answer on June 10, 2026 at 8:58 pm

    The common way to fix this would be to remove the while(){sleep} part and move the // Use self.currentLocation operations into the separate method called from locationManager:didUpdateToLocation:fromLocation: after you stop the manager. That is the most natural use of the delegate and you’ll want to use it. Other than that there are plenty of other solutions like adding observer to locationUpdatedFlag keypath or creating a separate thread manually to wait for it sleeping like you did.

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

Sidebar

Related Questions

I am trying to get the zip code of the users current location.I have
I'm trying to get my current GPS accuracy by using Location.getAccuracy() . However, this
I am trying to get an Current Altitude from location.getAltitude() method. but it always
I'm trying to get the current user login status via javascript sdk but I
I'm trying to get my current location and show it on a map. Class
I am trying to get the name of the city of user's current location
I'm trying to get the users current latitude and longitude with this viewDidLoad method.
I am trying to get current location of user using CLLocationCoordinate2D. I want the
I'm trying to get the current location using the iphone sdk. Here is the
I am trying to get my current location using cllocationmanager. Problem: The delegate method

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.