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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:08:13+00:00 2026-06-11T13:08:13+00:00

I have an array of points on a map. I populate the array correctly

  • 0

I have an array of points on a map.
I populate the array correctly and I make annotations for them on the map. everything is working fine.
I have another tableview with the same array, and in the “subtitle” of the cells, I calculate the distance to user and present. everything working fine.

Now,I want to sort the list in the table view, in other words I want to sort the same array by distance, lowest to highest.

The thing is that the distance is not part of the array. so how can I cross match the distance with the array, so that when I sort the distance, it takes its belonging object in the array with it and sorts the array as well?

I am fairly new to ios but I have managed to release 3 apps now, and this one is the fourth, far more complex and I think I have covered pretty good ground with making the app so far. From the mapview, to the tableview with a search controller and everything. I am only missing the sorting.

I imagine I need to add some tag or property to each object in the array and assign it to each distance in the distance array.
Any suggestions would be appreciated 🙂
Thanks in advance.

  • 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-11T13:08:14+00:00Added an answer on June 11, 2026 at 1:08 pm
    // Assuming you have your points on the map in an NSArray called
    // pointsOnMapArray and your distances in distanceArray, create a
    // new mutable array to hold both.  Note, the "distances" in this
    // case are stored as NSStrings.  We'll want to convert them to
    // doubles before sorting them.
    NSMutableArray *newArray = [[NSMutableArray alloc] init];
    
    // Iterate over all of the points, and add a new element to the mutable
    // array which is a new array containing a point and its distance.  The
    // distance is converted from an NSString to an NSNumber containing a
    // doubleValue.
    int i;   
    for (i = 0; i < pointsOnMapArray.count; i++) {
        NSArray *newItem = [NSArray arrayWithObjects: [pointsOnMapArray objectAtIndex: i], [NSNumber numberWithDouble:[[distanceArray objectAtIndex: i] doubleValue]], nil];
        [newArray addObject: newItem];
    }
    
    // Now, sort the new array based upon the distance in the second element
    // of each array (ie, the distance).
    [newArray sortUsingComparator: ^(id obj1, id obj2) {
        NSNumber *dist1 = [obj1 objectAtIndex:1];
        NSNumber *dist2 = [obj2 objectAtIndex:1];
    
        return [dist1 compare:dist2];
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two dimensional array of points, which constitute a map. The black
I have a map with multiple markers, which I populate via an array. Each
I have an array of points to be drawn on a map, its already
I have an array of points in unknown dimensional space, such as: data=numpy.array( [[
We have an array of points through which we would like to draw a
Possible Duplicate: checking if pointer points within an array If I have an array
I have a very simple array (please focus on the object with "points.bean.pointsBase" as
I have a large array of lat/lng points. Could be up to 20k points.
I have a map. On this map I have points, and when you click
I am using a multidimensional boolen array as a map/relief/mountain. So basicly, I have:

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.