2011-10-08 1 views
0

아래 코드는 내가 지금까지 사용해 왔던 것이며, 배열의 모든 객체를 올바르게 반복하지만, 모든 맵을 하나의 맵에 표시하려고 할 때 어레이에있는 마지막 obeject 만 맵에 추가합니다. 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는

답변

0

왜 당신은 주석을 작성하는 루프의 내부지도를 설정?

여기에 오래된 블로그 포스팅이지만, 기초를 설명하고 트랙

당신은 아마도지도보기의 주석 배열을 다시 귀하의 for 루프, 내부 [super viewDidLoad]를 호출하는 것처럼 보이는
+0

나는 각각의 ID에 대한 주석을 작성한 다음 각 루프 반복마다 새 주석을 작성할 것이라고 생각했지만 마지막 것에 도달 할 때까지 재정의했다. 링크를 잊어 버렸습니다. 감사합니다. –

1

에 다시 당신을 얻을 것이다. 이 메서드는 한 번만 호출해야하므로 for 문 앞에 이동하면 더 나은 결과를 얻을 수 있습니다.

+0

아론 (Aaron)이 지적한 것처럼'for' 루프 안에서 MapView를 설정하기 위해 수행하는 다른 작업은 실제로 20 번 수행 할 필요가 없습니다. 그러나 '[super viewDidLoad]'를 호출하면 주석. 실제로, // '지도 설정'과 '// 주석 지점 설정'사이의 모든 것이 for 루프 바깥으로 옮겨 져야합니다. –

+0

두 줄 : region.center.latitude = latDouble; region.center.longitude = longDouble; 각 배열 객체의 위도와 경도를 정의하는 것은 무엇입니까? 내가 시도 할게, 고마워! –

관련 문제