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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:48:46+00:00 2026-06-14T12:48:46+00:00

I have the following code in the .m file. The code is to perform

  • 0

I have the following code in the .m file.

The code is to perform the following tasks:

  1. initialize the CLLocationManager class
  2. obtain the properties (Speed, Accuracy, Coordinates)
  3. convert these values to NSString
  4. log these values to the screen via use of NSLog
  5. set the values in the designated labels and then finally
  6. loop thru the code contained in method “locationUpdate”.

The code provides an initial value for all these properties. However, the values are the same for every property (i.e. 2.7188880).

In addition, the code returns 0 for each property as I loop thru the method “locationUpdate”.

Can anyone tell me the reason the code isn’t returning values for the properties?

- (void)viewDidLoad {
    [super viewDidLoad];
    locationManager = [[CLLocationManager alloc] init];

    [locationManager setDelegate:self];

    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];

    [locationManager startUpdatingLocation];

    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval: 2.0
                                                      target: self
                                                    selector:@selector(locationUpdate)
                                                    userInfo: nil repeats:YES];

    [[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];


    NSString *spd = [[NSString alloc] initWithFormat:@"%f", speed];

    NSString *crd = [[NSString alloc] initWithFormat:@"%f", coordinates];

    NSString *drc = [[NSString alloc] initWithFormat:@"%f", direction];

    NSString *acc = [[NSString alloc] initWithFormat:@"%f", accuracy];

    NSString *desc = [locationManager description];

    NSLog(@"Speed: %@", spd);
    NSLog(@"Coordinates: %@", crd);
    NSLog(@"Direction: %@", drc);
    NSLog(@"Accuracy: %@", acc);
    NSLog(@"Description: %@", desc);

    Speedometer.text = spd;
    CoordinatesLabel.text = crd;
    DirectionLabel.text = drc;
    AccuracyLabel.text = acc;
    DescriptionLabel.text = desc; 
}


- (void)locationUpdate {

    NSString *desc = [locationManager description];

    NSString *spd = [NSString stringWithFormat:@"%g", speed];
    NSString *crd = [NSString stringWithFormat:@"%g", coordinates];

    NSString *drc = [NSString stringWithFormat:@"%g", direction];

    NSString *acc = [NSString stringWithFormat:@"%g", accuracy];

    NSLog(@"Speed: %@", spd);
    NSLog(@"Coordinates: %@", crd);
    NSLog(@"Direction: %@", drc);
    NSLog(@"Accuracy: %@", acc);

    Speedometer.text = spd;
    CoordinatesLabel.text = crd;
    DirectionLabel.text = drc;
    AccuracyLabel.text = acc;
    DescriptionLabel.text = desc; 
}
  • 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-14T12:48:47+00:00Added an answer on June 14, 2026 at 12:48 pm

    You are not supposed to setup a timer. You simply implement the location manager delegate methods. When there is an update, you will be told.

    Your biggest issue is your use of the variables speed, coordinates, direction, and accuracy. You never set them anywhere (at least with any code you posted).

    Implement the locationManager:didUpdateLocations: and/or locationManager:didUpdateToLocation:fromLocation: methods. These will be called with updated location information. Use these to update your speed and other ivars.

    Edit: One other suggestion. Don’t use string formats to format numbers to be displayed to the user. Use NSNumberFormatter instead. This way the numbers are formatted properly based on the user’s locale.

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

Sidebar

Related Questions

I have written the following code to perform some simultaneous HTTP posting and file
I have the following code to perform FTP file: private bool InitFTPTransfer(string filePath) {
I have the following json code file named: sections.json { section1: { priority: 1,
I am working with NSCache in iOS i have following code in .h file
I have the following code reading a file containing unicode text (Japanese). File f
When I using the following code to read file: lines=file(data.txt).read().split(\n) I have the following
Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
I have the following code in one cpp file which is part of a
I have the following code that returns a .CSV file when a link is
i have the following code snippet in my ANT File which compiles my project

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.