Note that there are some explanatory texts on larger screens.

plurals
  1. POChanged order of objects in array without calling for it
    text
    copied!<p>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:</p> <pre><code>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 &amp;&amp; placemarks.count &gt; 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]; }` </code></pre> <p>The log statements for before and after the the code block respectively (separated by asterisks) are:</p> <p><strong>Location coordinates: 40.116903,-75.120631<br> Location coordinates: 40.129940,-75.060127<br> Location coordinates: 40.083996,-75.187704<br> Location coordinates: 40.069180,-75.126812<br> Location coordinates: 40.095425,-75.127777<br> Location coordinates: 40.095019,-75.126752<br> Location coordinates: 40.117596,-75.185366<br> Location coordinates: 40.105838,-75.212272<br> Location coordinates: 40.124327,-75.061865<br> Location coordinates: 40.010910,-75.127223<br> Location coordinates: 40.061088,-75.092801<br> Location coordinates: 40.112011,-75.165353<br> Location coordinates: 40.017103,-75.174498<br> Location coordinates: 40.139532,-75.207757<br> Location coordinates: 40.099432,-75.196213</strong> </p> <hr> <p><strong>Location coordinates: 40.116903,-75.120631<br> Location coordinates: 40.061088,-75.092801<br> Location coordinates: 40.010910,-75.127223<br> Location coordinates: 40.124327,-75.061865<br> Location coordinates: 40.112011,-75.165353<br> Location coordinates: 40.099432,-75.196213<br> Location coordinates: 40.139532,-75.207757<br> Location coordinates: 40.017103,-75.174498<br> Location coordinates: 40.083996,-75.187704<br> Location coordinates: 40.069180,-75.126812<br> Location coordinates: 40.129940,-75.060127<br> Location coordinates: 40.095019,-75.126752<br> Location coordinates: 40.117596,-75.185366<br> Location coordinates: 40.095425,-75.127777<br> Location coordinates: 40.105838,-75.212272</strong> </p> <p>Any help would be much appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload