ios - Can't set different value for different dictionary -


i loop through nsdictionaries calculate distance user location annotations this:

cllocation *pinlocation = [[cllocation alloc]                                        initwithlatitude:reallatitude                                        longitude:reallongitude];  cllocation *userlocation = [[cllocation alloc]                                         initwithlatitude:mapview.userlocation.coordinate.latitude                                         longitude:mapview.userlocation.coordinate.longitude];  cllocationdistance distance = [pinlocation distancefromlocation:userlocation]; 

the result:

nslog(@"distance: %4.0f m.", distance);  2013-05-04 15:58:53.301 testapp[3194:907] distance: 65758 m. 2013-05-04 15:58:53.304 testapp[3194:907] distance: 91454 m. 2013-05-04 15:58:53.308 testapp[3194:907] distance: 248726 m. 2013-05-04 15:58:53.310 testapp[3194:907] distance: 297228 m. 2013-05-04 15:58:53.313 testapp[3194:907] distance: 163058 m. 

then try add distance dictionaries in array

nsstring *dist = [nsstring stringwithformat:@"%4.0f m.", distance];  [ann setvalue:dist forkey:@"distance"]; 

but add last distance (distance: 163058 m.) dictionaries.

how can set different value different dictionary?

edit: loop

    if ([[nsuserdefaults standarduserdefaults] boolforkey:@"bluekey"])     {          ann = [dict objectforkey:@"blue"];          [resultarray addobject:@"blue"];           for(int = 0; < [ann count]; i++) {               nsstring *coordinates = [[ann objectatindex:i] objectforkey:@"coordinates"];              double reallatitude = [[[coordinates componentsseparatedbystring:@","] objectatindex:1] doublevalue];             double reallongitude = [[[coordinates componentsseparatedbystring:@","] objectatindex:0] doublevalue];              myannotation *myannotation = [[myannotation alloc] init];             cllocationcoordinate2d thecoordinate;             thecoordinate.latitude = reallatitude;             thecoordinate.longitude = reallongitude;              myannotation.coordinate=cllocationcoordinate2dmake(reallatitude,reallongitude);             myannotation.title = [[ann objectatindex:i] objectforkey:@"name"];             myannotation.subtitle = [[ann objectatindex:i] objectforkey:@"address"];             myannotation.icon = [[ann objectatindex:0] objectforkey:@"icon"];              [mapview addannotation:myannotation];             [annotations addobject:myannotation];                // calculating distance             cllocation *pinlocation = [[cllocation alloc]                                        initwithlatitude:reallatitude                                        longitude:reallongitude];              cllocation *userlocation = [[cllocation alloc]                                         initwithlatitude:mapview.userlocation.coordinate.latitude                                         longitude:mapview.userlocation.coordinate.longitude];              cllocationdistance distance = [pinlocation distancefromlocation:userlocation];              // nslog(@"distance: %4.0f m.", distance);               nsstring *dist = [nsstring stringwithformat:@"%4.0f m.", distance];             [ann setvalue:dist forkey:@"distance"];           }        } 

you can add values in array , can use save in different dictionaries.

after line :

// nslog(@"distance: %4.0f m.", distance); 

add :

nsstring *dist = [nsstring stringwithformat:@"%4.0f m.", distance]; nsmutabledictionary *indict = [[nsmutabledictionary alloc] init]; indict = [ann objectatindex:i]; [indict setvalue:dist forkey:@"distance"]; 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -