Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding annotations in order -but map view does not return annotation in same order
    text
    copied!<p>I add my annotations as follows:</p> <pre><code> [mapView addAnnotations:annotationArray]; </code></pre> <p>then I want to access each and individual annotations on the mapView as follows:</p> <pre><code>for (id&lt;MKAnnotation&gt; ann in mapView.annotations) </code></pre> <p>the problem is annotations on map view is not added in a way linked list. That is why it is not returning in same order that I add annotations to annotationsArray.</p> <p>to illustrate:, </p> <pre><code> [annotationArray addObject: annotation1]; [annotationArray addObject: annotation2]; [annotationArray addObject: annotation3]; [mapView addAnnotations:annotationArray]; for (id&lt;MKAnnotation&gt; ann in mapView.annotations) { //not returning in same order as added above// } </code></pre> <p>Is there a bug in mapView annotation?</p> <p>original code:</p> <pre><code> NSMutableArray *attrArray=[[NSMutableArray alloc]init]; for (NSArray *row in latt) { NSNumber *attr=[row valueForKey:@"attr"]; NSNumber *attr2=[attr valueForKey:@"ozone_level"]; NSLog(@"values:%@",attr2); NSNumber *comp=[NSNumber numberWithInt:-1]; if(attr2!=comp) { if([attrArray count]==0) {attrArray=[[NSMutableArray alloc]initWithObjects:attr2, nil]; } else { [attrArray addObject:attr2]; } NSNumber *latt2=[row valueForKey:@"lat"]; NSNumber *longt2=[row valueForKey:@"lng"]; CLLocationCoordinate2D coordinate; coordinate.latitude=latt2.doubleValue; coordinate.longitude=longt2.doubleValue; if(test&lt;5) { Annotation *annotation = [[Annotation alloc] init]; annotation.coordinate = coordinate; annotation.title = [attr2 stringValue]; int colorvalue=[attr2 intValue]; pinColor = [self colorForAcceleration2:colorvalue]; annotation.color = pinColor; if([annotationArray count]==0) { annotationArray=[[NSMutableArray alloc]initWithObjects:annotation,nil]; // NSMutableArray *ad =[[NSMutableArray alloc]init]; } else { [annotationArray addObject:annotation]; } } test++; }//if attr2 }//for if( test == 5) { [mapView addAnnotations:annotationArray]; } if(test&gt;=5) { //for (id&lt;MKAnnotation&gt; ann in mapView.annotations) for(int i=0;i&lt;5;i++) { //Annotation *a = (Annotation *)ann; Annotation *a = ((Annotation*)[annotationArray objectAtIndex:i]); //((Annotation *)mapView.annotations). NSLog(@"%@",((Annotation*)[annotationArray objectAtIndex:i]).title); NSLog(@"%@",[attrArray objectAtIndex:i]); //NSLog(@"annotation array size:%d",[annotationArray count]); // NSLog(@"attr array size:%d",[attrArray count]); if([((Annotation*)[annotationArray objectAtIndex:i]).title isEqualToString:[[attrArray objectAtIndex:i] stringValue]]) { } else{ MKAnnotationView *av1=[mapView viewForAnnotation:((Annotation*)[annotationArray objectAtIndex:i])]; a.title=[NSString stringWithFormat:[[attrArray objectAtIndex:i] stringValue]]; int colorvalue=[[attrArray objectAtIndex:i] intValue]; pinColor = [self colorForAcceleration2:colorvalue]; a.color=pinColor; av1.image=[ZSPinAnnotation pinAnnotationWithColor:a.color]; av1.annotation=a;}//else }//for }//if </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload