ios - MKMapView is not showing annotated points -


i trying show location of current location , random 5 points points this:

- (void)viewdidload {     [super viewdidload];     locationmanager.delegate = self;     locationmanager.desiredaccuracy = kcllocationaccuracybest;      [locationmanager startupdatinglocation];     otherlat = [nsnumber numberwithdouble:[currentlatitude doublevalue]];     otherlong = [nsnumber numberwithdouble:[currentlongitude doublevalue]];      [self.mapview setshowsuserlocation:yes];     mapview.delegate = self;      longi = [[nsmutablearray alloc] init];     lati = [[nsmutablearray alloc] init];      nsmutablearray *la = [[nsmutablearray alloc] init];     nsmutablearray *lo = [[nsmutablearray alloc] init];     la = [nsmutablearray arraywithobjects:@"20", @"21", @"42", @"51", @"75", nil];     lo = [nsmutablearray arraywithobjects:@"60", @"21", @"82", @"181", @"35", nil];      (int x = 0; x < [la count]; x++) {         otherlat = [nsnumber numberwithdouble:[[la objectatindex:x] doublevalue]];         otherlong = [nsnumber numberwithdouble:[[lo objectatindex:x] doublevalue]];         [longi addobject:otherlong];         [lati addobject:otherlat];     }      myannotation *myannotation1 = [[myannotation alloc] init];     (int y = 0; y < [lati count]; y++) {           cllocationcoordinate2d thecoordinate;         thecoordinate.latitude = [[lati objectatindex:y] doublevalue];         thecoordinate.longitude = [[longi objectatindex:y] doublevalue];          myannotation1.coordinate = thecoordinate;         [mapview addannotation:myannotation1];     } }  - (mkannotationview *)mapview:(mkmapview *)themapview viewforannotation:(id <mkannotation>)annotation {     if ([annotation iskindofclass:[mkuserlocation class]])     return nil;      static nsstring *myannotationidentifier = @"annotationidentifier";     mkpinannotationview *custompinview = [[mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:myannotationidentifier];     custompinview.image = [uiimage imagenamed:@"purplepin.png"];     custompinview.animatesdrop = yes;     custompinview.canshowcallout = yes;      return custompinview; } 

however, mapview shows current location, , none of other 5 locations. not understand why not showing other 5 locations because

  [mapview addannotation:myannotation1]; 

you add 1 annotation. 5 times, overwrite previous coordinate.

//only 1 allocated , used/modified in every iteration of loop! myannotation* myannotation1=[[myannotation alloc] init]; (int y =0; y < [lati count]; y++) {       .... 

you need create not 1 myannotation1, ..... 5 separate ones:

//allocate & add in each iteration of loop! (int y =0; y < [lati count]; y++) {       myannotation* myannotation1=[[myannotation alloc] init];     .... 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -