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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:07:10+00:00 2026-06-18T10:07:10+00:00

I need to show on my MkMapView about 10 locations (and respective annotations) and

  • 0

I need to show on my MkMapView about 10 locations (and respective annotations) and after pressing a button I need to add new different annotations according to different JSON parsing results (for example a locationIDValue < 100 means a red pin, otherwise green). This is the simplified code:

- (void)viewDidLoad
{
    [super viewDidLoad];
    map.showsUserLocation = true;
    map.mapType = MKMapTypeStandard;

    arrayID = [[NSMutableArray alloc] initWithObjects: @"id1", @"id2", @"id3", @"id4", @"id5", @"id6", @"id7", @"id8", @"id9", @"id10", nil]; 

    #define MakeLocation(lat,lon) [[CLLocation alloc] initWithLatitude:lat longitude:lon]

    locations= @[ MakeLocation(lat1,lon1), MakeLocation(lat2,lon2), MakeLocation(lat3,lon3), MakeLocation(lat4,lon4), MakeLocation(lat5,lon5), MakeLocation(lat6,lon6), MakeLocation(lat7,lon7), MakeLocation(lat8,lon8), MakeLocation(lat9,lon9), MakeLocation(lat10,lon10) ];

    for (int l=0; l<[locations count]; l++) { // HERE ITS PERFECT! I CAN SEE ALL 10 ANNOTATIONS!
        MKPointAnnotation* annotation= [MKPointAnnotation new];
        annotation.coordinate = [locations[l] coordinate];
        [map addAnnotation: annotation];
    }
}

and

   - (IBAction)parseMethod {

        [map removeAnnotations:map.annotations];

        for (int i=0; i < [arrayID count]; i++) { // arrayID contains ID values to parse for each location

            NSURL *url = [NSURL URLWithString:
                          [NSString stringWithFormat:
                           @"http://JSONPARSINGURL/%@",[arrayID objectAtIndex:i]]];

            NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:5.0];
            operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {

        // PARSING CODE . . .

                NSMutableArray *value = [JSON objectForKey:@"value"];
                NSMutableDictionary *value0 = [value objectAtIndex:0];
                [valueID replaceObjectAtIndex:i withObject:[value0 objectForKey:@"valueID"]];
                locationIDValue = [[valueID objectAtIndex:i] intValue]; // locationIDValue contains the values that i must use to put different annotations on the map

                NSLog(@"locationIDValue: %d", locationIDValue); // here I control IF app parses all the values of locationIDValue

                [table reloadData]; // here I put another control to see all values parsed

            }
                                                                        failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) {
                                                                            NSLog(@"FAILURE");
                                                                        }];

            NSOperationQueue *queue = [[NSOperationQueue alloc] init]; // I have used also simple [operation start] but I have same issue!
            [queue addOperation:operation];
            [queue waitUntilAllOperationsAreFinished];

    }

        NSLog(@"END PARSING"); // here I control the end of parsing, so now I can add new annotations to MKMapView according to locationIDValue array

        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
        for (int l=0; l<[locations count]; l++) { // HERE I CAN SEE ONLY A SINGLE LOCATION!
            annotation.coordinate = [locations[l] coordinate];

            NSLog(@"%f - %f", annotation.coordinate.latitude, annotation.coordinate.longitude); // here I control IF app parses all the values of coordinates

            [map addAnnotation: annotation];
        }

    }

and

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {

    MKPinAnnotationView *pinView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"pinView"];
    pinView.animatesDrop=YES;

    if (annotation != map.userLocation)
    {
        if ( locationIDValue <= 100) {
            pinView.pinColor = MKPinAnnotationColorRed;
            return pinView;
        }
        pinView.pinColor = MKPinAnnotationColorGreen;
        return pinView;
    }
    else
    map.userLocation.title = @"My position";
    return nil;
}

The situation:
When I open app for the first time its all right, I can see ALL the annotations dropping on the map, according with the #define MakeLocation latitude and longitude; but if I press the button and start the parseMethod, I wait a few seconds (according to NSOperationQueue, but I can test it also without queue, with simple [operation start] code), then I can see ONLY ONE SINGLE annotation on the map, always the same, strangely on the FIFTH location, with lat5-lon5 coordinates (otherwise, if I change a few code I can see ALL THE ANNOTATIONS dropping on the SAME location). As u can see I write some NSLog code and add UITableView to control the activity, and this is the result:

END PARSING
coordinates: lat1 - lon1
coordinates: lat2 - lon2
coordinates: lat3 - lon3
coordinates: lat4 - lon4
coordinates: lat5 - lon5   <--- THE STRANGE POSITION
coordinates: lat6 - lon6
coordinates: lat7 - lon7
coordinates: lat8 - lon8
coordinates: lat9 - lon9
coordinates: lat10 - lon10
locationIDValue: 100
locationIDValue: 90
locationIDValue: 50
locationIDValue: 120
locationIDValue: 20
locationIDValue: 40
locationIDValue: 80
locationIDValue: 180
locationIDValue: 140
locationIDValue: 10

Well, it seems PERFECT: app parse all the data (also a UITableView populate rows with ALL the new values parsed), so AFTER the end of parsing operation I think we have EVERY value necessary to populate map with new annotations. Well, what is wrong here? Why after parsing I can only see a single annotation? Or, ALL annotations dropping ON THE SAME LOCATION? Please give me an help!

  • 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-18T10:07:11+00:00Added an answer on June 18, 2026 at 10:07 am

    In parseMethod, change this:

    MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    for (int l=0; l<[locations count]; l++) { // HERE I CAN SEE ONLY A SINGLE LOCATION!
        annotation.coordinate = [locations[l] coordinate];
    
        NSLog(@"%f - %f", annotation.coordinate.latitude, annotation.coordinate.longitude); // here I control IF app parses all the values of coordinates
    
        [map addAnnotation: annotation];
    }
    

    to this:

    for (int l=0; l<[locations count]; l++) { // HERE I CAN SEE ONLY A SINGLE LOCATION!
    
        //create a NEW annotation for each location...
        MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
    
        annotation.coordinate = [locations[l] coordinate];
    
        NSLog(@"%f - %f", annotation.coordinate.latitude, annotation.coordinate.longitude); // here I control IF app parses all the values of coordinates
    
        [map addAnnotation: annotation];
    }
    

    Move the MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init] to inside the for-loop so that a new annotation object is created for each location.

    The existing code there creates a single annotation object and just keeps modifying its coordinate.

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

Sidebar

Related Questions

I need help with MKMapView .In map i show pictures after click on picture
I need to show non available dates in different color based on the event
I need to show a form using a button, and hide it when the
I need to show different image on mousehover of Image . Presently i am
I need to show my current and target locations on google map with max
I am using MKMapView on my application. i need to show current location on
I need show a notication modal window.. But since its a fluid layout the
me again... I need show 10 or 20 or 50 results number of results
I need to show a form exactly in front of another form, this lead
I need to show a UIActionSheet on a popover and this popover has an

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.