I have a set of dictionaries in an array. I display this data in a tableview. In the tableview i calculate the distance to each object and display that in the cell.
You can easily sort with a the block based comparator api.
NSArray *rawData = [NSArray arrayWithContentsOfFile:pathDoc];
rawData = [rawData sortedArrayUsingComparator: ^(id a, id b) {
CLLocationDistance dist_a= [[a objectsForKey:@"coordinate"] distanceFromLocation: userPosition];
CLLocationDistance dist_b= [[b objectsForKey:@"coordinate"] distanceFromLocation: userPosition];
if ( dist_a < dist_b ) {
return NSOrderedAscending;
} else if ( dist_a > dist_b) {
return NSOrderedDescending;
} else {
return NSOrderedSame;
}
}];
You should easy find an implementation for calculate_distance(user_position, a);
with google.