下面的代碼是我到目前爲止所使用的代碼,它正確地遍歷數組中的每個對象,但是當我嘗試使它們全都顯示在一張地圖上時只會將數組中最後一個元素添加到地圖中,而不是全部20個左右我想要顯示。如何在基於數組的mapview上有多個註釋
self.clientTable = [ClientDatabase database].clientTable;
ClientTable *info = nil;
[_nameLabel setText:info.name];
[_stateLabel setText:info.state];
//change the string to doubles for the map GPS co-ordinates
double latDouble = [info.latMap doubleValue];
double longDouble = [info.longMap doubleValue];
NSLog(@"%d",[self.clientTable count]);
int countArray = [self.clientTable count];
for (int i=0;i<countArray;i++) {
info = [self.clientTable objectAtIndex:i];
info.uniqueId=i;
NSLog(@" i = %d ; id = %d %@",i, info.uniqueId, info.name);
//set up the map
[super viewDidLoad];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
MKCoordinateRegion region = {{0.0,0.0},{0.0,0.0}};
region.center.latitude = latDouble;
region.center.longitude = longDouble;
region.span.longitudeDelta =0.02; //degrees of acuracy, most precise best for this time
region.span.latitudeDelta =0.02; //degrees of accuracy
[mapView setRegion:region animated:YES];
// set up the annotation point
AllMap *annotationPoint = [[AllMap alloc] init];
annotationPoint.title = info.name;
annotationPoint.subtitle = info.state;
annotationPoint.coordinate = region.center;
[mapView addAnnotation:annotationPoint];
annotationPoint.isAccessibilityElement=YES;
//show annotation by default
[mapView selectAnnotation:annotationPoint animated:YES];
[mapView setDelegate:self];
}
對不起,如果代碼是垃圾,我是新的iPhone編程。
在此先感謝:d
我這樣做,因爲我認爲如果我爲每個ID創建一個註釋,那麼它會創建一個新的每個循環迭代,但它只是覆蓋它,直到最後一個達到然後顯示。 你也忘了附上一個鏈接。 謝謝! –