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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:54:21+00:00 2026-06-13T00:54:21+00:00

I have an array of CLLocation objects I parsed from a file. I’d want

  • 0

I have an array of CLLocation objects I parsed from a file. I’d want to simulate that the user is moving along that route, and I have implemented this:

for (CLLocation *loc in simulatedLocs) {
            [self moveUser:loc];
            sleep(1);
        }

This is the method called in the loop:

- (void)moveUser:(CLLocation*)newLoc
{
    CLLocationCoordinate2D coords;
    coords.latitude = newLoc.coordinate.latitude;
    coords.longitude = newLoc.coordinate.longitude;
    CustomAnnotation *annotation = [[CustomAnnotation alloc] initWithCoordinate:coords];
    annotation.title = @"User";

    // To remove the previous location icon
    NSArray *existingpoints = self.mapView.annotations;
    if ([existingpoints count] > 0) {
        for (CustomAnnotation *annotation in existingpoints) {
            if ([annotation.title isEqualToString:@"User"]) {
                [self.mapView removeAnnotation:annotation];
                break;
            }
        }
    }

    MKCoordinateRegion region = { coords, {0.1, 0.1} };
    [self.mapView setRegion:region animated:NO];
    [self.mapView addAnnotation: annotation];
    [self.mapView setCenterCoordinate:newLoc.coordinate animated:NO];
}

But only last location in the array and its region are displayed in the mapView when running the iPhone simulator. I’d like to simulate that user is “moving” each 1 sec, how could I do that?

Thanks!

  • 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-13T00:54:23+00:00Added an answer on June 13, 2026 at 12:54 am

    Looping through all the locations all at once with a sleep at each iteration won’t work because the UI will be blocked until the method the loop is in finishes.

    Instead, schedule the moveUser method to be called individually for each location so that the UI is not blocked throughout the sequence. The scheduling can be done using an NSTimer or possibly something simpler and more flexible such as the performSelector:withObject:afterDelay: method.

    Keep an index ivar to keep track of which location to move to each time moveUser is called.

    For example:

    //instead of the loop, initialize and begin the first move...
    slIndex = 0;  //this is an int ivar indicating which location to move to next
    [self manageUserMove];  //a helper method
    
    -(void)manageUserMove
    {
        CLLocation *newLoc = [simulatedLocs objectAtIndex:slIndex];
    
        [self moveUser:newLoc];
    
        if (slIndex < (simulatedLocs.count-1))
        {
            slIndex++;
            [self performSelector:@selector(manageUserMove) withObject:nil afterDelay:1.0];
        }
    }
    

    The existing moveUser: method does not have to be changed.

    Note that the user experience and code can be simplified if instead of removing and adding the annotation again every time, you add it once at the beginning and just change its coordinate property at each “move”.

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

Sidebar

Related Questions

i have an array that named detailTexts that having his data from floats: CLLocation
I have an array of CLLocation objects and I'd like to be able to
I have an Array of MKAnnotation objects called arrAnnotations . I want to pick
hi i have an array of cllocation values, i need to store that array
I have an app that tracks a user as they drive along. It uses
When I have array of objects, when I type the name of variable in
I have array of country names and i want to get coordinates of them
I have a MKMapView (obviously), that shows housing locations around the user. I have
I have a block of code that adds an object to an array declared
I have a class that contains a dynamically allocated array, say class A {

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.