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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:22+00:00 2026-05-23T23:09:22+00:00

I’m working on an application using the MapKit in iOS. I’m having trouble because

  • 0

I’m working on an application using the MapKit in iOS. I’m having trouble because at some point during my program, the order of one of the arrays switches (the array holding the coordinates), causing names of places to be paired with the wrong coordinates. I have narrowed it down to the following area:

for(CLLocation *loc in locationOutputArray)
{
    NSLog(@"Location coordinates: %f,%f",[loc coordinate].latitude,
                                         [loc coordinate].longitude);
}
NSLog(@"***************************************");
for(CLLocation *location in locationOutputArray)
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:location
                   completionHandler:^(NSArray *placemarks, NSError *error)
     {

         NSLog(@"Location coordinates:%f,%f",[location coordinate].latitude,
                                             [location coordinate].longitude);
         if(placemarks && placemarks.count > 0)
         {
             CLPlacemark *topResult = [placemarks objectAtIndex:0];

             //NSLog(@"%@",topResult);

             NSString *address = [NSString stringWithFormat:@"%@ %@, %@ %@",
                                  [topResult subThoroughfare],
                                  [topResult thoroughfare],
                                  [topResult locality],
                                  [topResult administrativeArea]];
             //NSLog(@"Address: %@", address);

             [addressOutputArray addObject:address];


             Place *place = [[Place alloc]
                             initWithName:[namesOutputArray objectAtIndex:([addressOutputArray count]-1)]
                               andAddress:address
                              andLatitude:[location coordinate].latitude 
                             andLongitude:[location coordinate].longitude
                    andStartingCoordinate:startingCoordinate];

             //NSLog(@"Distance from starting location: %f",[place distanceFromStartingPoint]);

             [finalPlaceArray addObject:place];
             [place release];
}`

The log statements for before and after the the code block respectively (separated by asterisks) are:

Location coordinates: 40.116903,-75.120631
Location coordinates: 40.129940,-75.060127
Location coordinates: 40.083996,-75.187704
Location coordinates: 40.069180,-75.126812
Location coordinates: 40.095425,-75.127777
Location coordinates: 40.095019,-75.126752
Location coordinates: 40.117596,-75.185366
Location coordinates: 40.105838,-75.212272
Location coordinates: 40.124327,-75.061865
Location coordinates: 40.010910,-75.127223
Location coordinates: 40.061088,-75.092801
Location coordinates: 40.112011,-75.165353
Location coordinates: 40.017103,-75.174498
Location coordinates: 40.139532,-75.207757
Location coordinates: 40.099432,-75.196213


Location coordinates: 40.116903,-75.120631
Location coordinates: 40.061088,-75.092801
Location coordinates: 40.010910,-75.127223
Location coordinates: 40.124327,-75.061865
Location coordinates: 40.112011,-75.165353
Location coordinates: 40.099432,-75.196213
Location coordinates: 40.139532,-75.207757
Location coordinates: 40.017103,-75.174498
Location coordinates: 40.083996,-75.187704
Location coordinates: 40.069180,-75.126812
Location coordinates: 40.129940,-75.060127
Location coordinates: 40.095019,-75.126752
Location coordinates: 40.117596,-75.185366
Location coordinates: 40.095425,-75.127777
Location coordinates: 40.105838,-75.212272

Any help would be much appreciated.

  • 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-05-23T23:09:23+00:00Added an answer on May 23, 2026 at 11:09 pm

    Short answer: You’re printing the locations in the order that the geocoder requests complete, not the order in which they appear in the array.

    Longer answer: You’re making a bunch of calls to the geocoder (one call for each location in your array), and passing in a completion handler. Those calls are asynchronous, which means that you’re not waiting for one to complete before you fire off the next one. When each call completes, you print its location. So, the output you’re getting represents the order in which the calls are completing, not the order in which the locations appear in the original array or the order that you made the calls.

    Solution: Don’t rely on asynchronous calls to complete in any particular order. If you need the results to appear in some order, you’ll need a way to sort them. It sounds like you’re keeping place names and locations in separate arrays and trying to keep those arrays ordered the same. That’s always a recipe for bugs; you’d be better off keeping everything in a single array, where each entry in the array contains both place name and location. Using a dictionary for each place may be a convenient way to achieve that.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests
I'm parsing an XML file, the creators of it stuck in a bunch social

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.