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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:25:26+00:00 2026-05-23T17:25:26+00:00

I’m currently adding annotations to my map through a loop… but the annotations are

  • 0

I’m currently adding annotations to my map through a loop… but the annotations are only appearing on my map in groups. Also, on load, only about 4 annotations are actually displayed on the map… but as I move the map a little, all of the annotations that should be there, suddenly appear.

How can I get all of the annotations to load in the right place, one at a time?

Thanks in advance!

Here is the code I’m using to add annotations:

 NSString *incident;
            for (incident in weekFeed) {
                NSString *finalCoordinates = [[NSString alloc] initWithFormat:@"%@", [incident valueForKey:@"coordinates"]];

                NSArray *coordinatesArray = [finalCoordinates componentsSeparatedByString:@","]; 

                latcoord = (@"%@", [coordinatesArray objectAtIndex:0]);
                longcoord = (@"%@", [coordinatesArray objectAtIndex:1]);

                // Final Logs
                NSLog(@"Coordinates in NSString: [%@] - [%@]", latcoord, longcoord);

                CLLocationCoordinate2D coord;
                coord.latitude = [latcoord doubleValue];
                coord.longitude = [longcoord doubleValue];


                DisplayMap *ann = [[DisplayMap alloc] init]; 
                ann.title = [NSString stringWithFormat: @"%@", [incident valueForKey:@"incident_type"]];
                ann.subtitle = [NSString stringWithFormat: @"%@", [incident valueForKey:@"note"]];
                ann.coordinate = coord;

                [mapView addAnnotation:ann];

                [ann release];
                }


// Custom Map Markers
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {

    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;  //return nil to use default blue dot view

    static NSString *AnnotationViewID = @"annotationViewID";
    MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];

    if (annotationView == nil) {
        annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
        }

    annotationView.canShowCallout = YES;

    if ([annotationView.annotation.title isEqualToString:@"one"]) {
        UIImage *pinImage = [UIImage imageNamed:@"marker_1.png"];
        [annotationView setImage:pinImage];
        }

    if ([annotationView.annotation.title isEqualToString:@"two"]) {
        UIImage *pinImage = [UIImage imageNamed:@"marker_2.png"];
        [annotationView setImage:pinImage];
        }

    annotationView.annotation = annotation;
    return annotationView;
    }

- (void) mapView:(MKMapView *)mapV didAddAnnotationViews:(NSArray *)views {
    CGRect visibleRect = [mapV annotationVisibleRect]; 
    for (MKAnnotationView *view in views) {
        CGRect endFrame = view.frame;

        CGRect startFrame = endFrame; startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
        view.frame = startFrame;

        [UIView beginAnimations:@"drop" context:NULL]; 
        [UIView setAnimationDuration:0.4];

        view.frame = endFrame;

        [UIView commitAnimations];
    }
}
  • 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-23T17:25:27+00:00Added an answer on May 23, 2026 at 5:25 pm

    Adam,

    This solution is a bit messy as I had to munge up one of my current projects to test, but hopefully this will work for you.

    First an explanation, it’s critical to separate data from UI presentation. The [MKMapView addAnnotation(s)] are just a data update to MKMapView and have no direct impact on animation or timing.

    The delegate method mapView:didAddAnnotationViews: is where all of the custom presentation behavior should be defined. In your description you didn’t want these to appear all at once, so you need to sequence your animations instead of performing them simultaneously.

    One method is to add all of the annotations at once and then just add them with increasing animation delays, however new annotations that get added for whatever reason will begin their animations at zero again.

    The method below sets up an animation queue self.pendingViewsForAnimation (NSMutableArray) to hold annotation views as they are added and then chains the animation sequentially.

    I’ve replaced the frame animation with alpha to focus on the animation problem to separate it from the issue of some items not appearing. More on this after the code…

    // Interface
    // ...
    
    // Add property or iVar for pendingViewsForAnimation; you must init/dealloc the array
    @property (retain) NSMutableArray* pendingViewsForAnimation;
    
    // Implementation
    // ...
    - (void)processPendingViewsForAnimation
    {
        static BOOL runningAnimations = NO;
        // Nothing to animate, exit
        if ([self.pendingViewsForAnimation count]==0) return;
        // Already animating, exit
        if (runningAnimations) 
            return;
    
        // We're animating
        runningAnimations = YES;
    
        MKAnnotationView* view = [self.pendingViewsForAnimation lastObject];
    
        [UIView animateWithDuration:0.4 animations:^(void) {
            view.alpha = 1;
            NSLog(@"Show Annotation[%d] %@",[self.pendingViewsForAnimation count],view);
        } completion:^(BOOL finished) {
            [self.pendingViewsForAnimation removeObject:view];
            runningAnimations = NO;
            [self processPendingViewsForAnimation];
        }];
    
    }
    
    // This just demonstrates the animation logic, I've removed the "frame" animation for now
    // to focus our attention on just the animation.    
    - (void) mapView:(MKMapView *)mapV didAddAnnotationViews:(NSArray *)views {
        for (MKAnnotationView *view in views) {
            view.alpha = 0;
    
            [self.pendingViewsForAnimation addObject:view];
        }
        [self processPendingViewsForAnimation];
    }
    

    Regarding your second issue, items are not always appearing until you move the map. I don’t see any obvious errors in your code, but here are some things I would do to isolate the problem:

    1. Temporarily remove your mapView:didAddAnnotationViews:, mapView:annotationForView: and any other custom behaviors to see if default behavior works.
    2. Verify that you have a valid Annotation at the addAnnotation: call and that the coordinates are visible (use [mapView visibleMapRect], MKMapRectContainsPoint(), and MKMapPointForCoordinate().
    3. If it is still not functioning, look at where you are calling the add annotations code from. I try to avoid making annotation calls during map movement by using performSelector:withObject:afterDelay. You can precede this with an [NSObject cancelPreviousPerformRequestsWithTarget:selector:object:] to create a slight delay prior to loading annotations in case the map is being moved a long distance with multiple swipes.

    One last point, to achieve the pin-drop effect you’re looking for, you probably want to offset by a fixed distance from the original object instead of depending on annotationVisibleRect. Your current implementation will result in pins moving at different speeds depending on their distance from the edge. Items at the top will slowly move into place while items at the bottom will fly rapidly into place. Apple’s default animation always drops from the same height. An example is here: How can I create a custom "pin-drop" animation using MKAnnotationView?

    Hope this helps.

    Update:
    To demonstrate this code in action I’ve attached a link to a modified version of Apple’s Seismic demo with the following changes:

    1. Changed Earthquake.h/m to be an MKAnnotation object
    2. Added SeismicMapViewController.h/m with above code
    3. Updated RootViewController.h/m to open the map view as a modal page

    See: http://dl.dropbox.com/u/36171337/SeismicXMLWithMapDelay.zip

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

Sidebar

Related Questions

I want use html5's new tag to play a wav file (currently only supported
I am trying to loop through a bunch of documents I have to put
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.