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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:44:47+00:00 2026-05-18T21:44:47+00:00

I have an NSArray of 500 annotations and I basically want to show only

  • 0

I have an NSArray of 500 annotations and I basically want to show only the ten nearest annotations to the user (the rest would not be added on Mapview)

How should I do that?

Here is my code:

-(void) loadAndSortPOIs {
 [poiArray release];
 nextPoiIndex = 0;
 NSString *poiPath = [[NSBundle mainBundle] pathForResource:@"annotations"
              ofType:@"plist"];
 poiArray = [[NSMutableArray alloc] initWithContentsOfFile:poiPath];
 CLLocation *homeLocation = [[CLLocation alloc] 
        initWithLatitude:homeCoordinate.latitude
        longitude:homeCoordinate.longitude];
 for (int i = 0; i < [poiArray count]; i++) {
  NSDictionary *dict = (NSDictionary*) [poiArray objectAtIndex: i];
  CLLocationDegrees storeLatitude = [[dict objectForKey:@"workingCoordinate.latitude"] doubleValue];
  CLLocationDegrees storeLongitude = [[dict objectForKey:@"workingCoordinate.longitude"] doubleValue];
  CLLocation *storeLocation = [[CLLocation alloc]
          initWithLatitude:storeLatitude
          longitude:storeLongitude];
  CLLocationDistance distanceFromHome = [storeLocation distanceFromLocation: homeLocation];
  [storeLocation release];


  NSMutableDictionary *mutableDict = [[NSMutableDictionary alloc]
           initWithDictionary:dict];
  [mutableDict setValue:[NSNumber numberWithDouble:distanceFromHome]
        forKey:@"distanceFromHome"];
  [poiArray replaceObjectAtIndex:i withObject:mutableDict];
  [mutableDict release];

 }


// now sort by distanceFromHome

 NSArray *sortDescriptors = [NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"distanceFromHome" ascending:YES] autorelease]];

 [poiArray sortUsingDescriptors:sortDescriptors];
 NSLog (@"poiArray: %@", poiArray);

 [homeLocation release];

EDIT: I’ve added this to my code, but it still doesn’t work…

- (void) displayPois {
    [mapView removeAnnotations: mapView.annotations];
for(int i = 0; i < 10; i++) {
    NSDictionary *poiDict = [poiArray objectAtIndex:nextPoiIndex++];
    CLLocationCoordinate2D poiCoordinate;
    poiCoordinate.latitude = [[poiDict valueForKey:@"workingCoordinate.latitude"] doubleValue];
    poiCoordinate.longitude = [[poiDict valueForKey:@"workingCoordinate.longitude"] doubleValue];
    MyHomeAnnotation *poiAnnotation = [[MyHomeAnnotation alloc]
                                       initWithCoordinate:poiCoordinate
                                       title:[poiDict valueForKey:@"Subtitle"]
                                       ];
        [mapView addAnnotation:poiAnnotation];
        [self loadAndSortPOIs];
    [poiAnnotation release];

    }   [self adjustMapZoom];
}
  • 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-18T21:44:48+00:00Added an answer on May 18, 2026 at 9:44 pm

    The addAnnotations method expects an array of objects that conform to the MKAnnotation protocol. The array you are passing it seems to just contain plain dictionary objects.

    You’ll need to replace the addAnnotations line with a loop that goes through your annotations array and creates an MKPointAnnotation object from each dictionary object (pull out the coordinates and init the MKPointAnnotation object with them). Then (inside the for-loop) call addAnnotation (singular) and pass it the MKPointAnnotation object.

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

Sidebar

Related Questions

I have an NSArray of Foos in an Objective-C program. I would like to
I have an NSArray of NSDictionary objects which I would like to be able
I have an NSArray built from json data from twitter REST API. NSArray *dict
I have an NSArray with several NSDictionaries . I want to create a new
I have an NSArray of Strings and what I want to do is create
I have an NSArray of strings and I want to add a certain amount
I have a NSArray containing objects. I want to create a secondary NSArray containing
I have a first NSArray firstArray and I do [firstArray removeAllObjects]; after I want
I have an NSArray of NSDate objects and I want to sort them so
I have a NSArray with numbers and I want to get the value of

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.