2012-04-13 3 views
5

mapview에 여러 개의 주석 (arround 500)을 추가하고 싶지만 표시되는 최대 값은 100입니다. 100을 넘으면 viewForAnnotation 대리자 메서드가 호출되지 않습니다. 그러나 여기에 100MKMapView에서 그릴 수있는 주석 (MKAnnotation)의 최대 개수는 무엇입니까?

아래 주석 완벽하게 작동 코드이다 : (에만 작동 annotationArray 어레이의 수가 적은 (101)를 초과 할 때)

_allPoints = [[NSMutableArray alloc] init]; 

NSString* responseFile = [[NSBundle mainBundle] pathForResource:@"Datafile" ofType:@"txt"]; 
NSData *sampleData = [NSData dataWithContentsOfFile:responseFile]; 
if (sampleData) { 
    NSError* error; 
    NSDictionary* json = [NSJSONSerialization 
          JSONObjectWithData:sampleData 

          options:kNilOptions 
          error:&error]; 

    NSArray* response = [json objectForKey:@"response"]; 
    for (NSDictionary *lineDict in response) { 
     if ([[lineDict objectForKey:@"data"] isKindOfClass:[NSArray class]]) { 
      SinglePoint *singlePoint = [[SinglePoint alloc] initWithDictionary:lineDict]; 
      [_allPoints addObject:singlePoint]; 
     } 
     else { 
      NSLog(@"Error"); 
     } 
    } 
} 


_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
[_mapView setDelegate:self]; 
[self.view addSubview:_mapView]; 

NSMutableArray *annotationArray = [[NSMutableArray alloc] init]; 
for (int i=0; i<[_allPoints count]; i++) { 
    SinglePoint *singlePoint = [_allPoints objectAtIndex:i]; 
    NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoint:singlePoint mapView:_mapView]; 
    [annotationArray addObject:annotation]; 
} 
[_mapView addAnnotations:(NSArray *)annotationArray]; 

CLLocationCoordinate2D centerCoord = { 28.632747, 77.219982 }; 
[_mapView setCenterCoordinate:centerCoord zoomLevel:12 animated:NO]; 

위임 방법이다

편집 : 의견 당, 재사용 시작했지만 행운을 빌어 요. (

if ([annotation isKindOfClass:[NVPolylineAnnotation class]]) { 
    static NSString *viewIdentifier = @"annotationView"; 
    NVPolylineAnnotationView *annotationView = (NVPolylineAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:viewIdentifier]; 
    if (annotationView == nil) { 
     annotationView = [[NVPolylineAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:viewIdentifier mapView:_mapView]; 
    } 
    return annotationView; 
} 
return nil; 

설명서 또는 그 밖의 다른 곳에서는 제한을 찾을 수 없습니다. 메모리 문제일까요?

+1

당신이 당신의'annotationArray'에'allPoints' 500 회에서 첫 번째 개체를 추가하면 어떻게됩니까? –

+0

'NVPolylineAnnotation'에 대한 소스 코드를 제공 할 수 있습니까? –

답변

0

마지막으로 문제를 추적 할 수있었습니다. 먼저 mapView의 중심을 설정하고 나중에 주석을 추가하여이를 해결했습니다. 나는 왜 100 개의 주석이 더 일찍 표시되었는지 (그리고 왜 100 번만 표시되는지) 알지 못한다. 귀하의 제안과 시간을 내 주셔서 감사합니다.

이 내가 변경 한 코드는 다음과 같습니다 -

_mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)]; 
[_mapView setDelegate:self]; 
[self.view addSubview:_mapView]; 

CLLocationCoordinate2D centerCoord = { 28.632747, 77.219982 }; 
[_mapView setCenterCoordinate:centerCoord zoomLevel:12 animated:NO]; 

NSMutableArray *annotationArray = [[NSMutableArray alloc] init]; 
for (int i=0; i<[_allPoints count]; i++) { 
    SinglePoint *singlePoint = [_allPoints objectAtIndex:i]; 
    NVPolylineAnnotation *annotation = [[NVPolylineAnnotation alloc] initWithPoint:singlePoint mapView:_mapView]; 
    [annotationArray addObject:annotation]; 
} 
[_mapView addAnnotations:(NSArray *)annotationArray]; 
+0

모든 주석 포인트를 묶는'MKCoordinateRegion'을 구성하여 하드 코딩 된 위도와 경도를 피하고 [setRegion : animated :] (http://developer.apple.com/library/ios/#)를 사용할 수 있습니까? documentation/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html # // apple_ref/occ/instm/MKMapView/setRegion : animated :)지도를 어떤 위치에 두거나 줌이 필요합니까? (포인트가 없으면 폴백해야합니다. 그렇지 않으면 예외가 발생합니다.) – Dondragmer

+0

해답을 제공해 주셔서 감사합니다. –

1

MKMapView에는 annotationViews에 대한 제한이 없습니다. 그러나 특정 시점 (+1000) 이상에서는 상당히 지체되어 사용할 수 없습니다.

나는이 이유가 당신이 annotationView 경영을 완전히 잘못 처리하고 있다고 생각합니다. ARC를 사용하는 경우에도 모든 단일 주석에 대해 고유 한보기를 만들면 안됩니다. 오히려 UITableView 셀처럼 사용하지 않는 모든 뷰를 재사용해야합니다.

여기에는 Introduction to MapKit on iOS - Ray Wenderlich과 같은 몇 가지 좋은 설명서가 있습니다.

이렇게해도 문제가 해결되지 않으면 주석 클래스를 디버깅해야합니다. (NVPolylineAnnotationNVPolylineAnnotationView). 어쩌면 뭔가 잘못 됐을 수도 있습니다. 동일한 좌표에 대해 점 배열을 검사 했습니까?

+1

고마워요 @yinkou .. 1) 나는 101의 전망이있을 때 정확하게 생기기 때문에 문제는 기억 관리에다는 것을 생각하지 않는다. 2) 동등한 좌표에 대한 점을 확인했지만 아무 것도 없다. 어떤 점이 같을지라도, 내가 볼 수있는 나머지 100 점을 그려야합니다. – Shri

+0

맞습니다. 그럼에도 불구하고 권장되는 패턴이므로 annotationViews를 다시 사용해야합니다. _allPoints 배열을 만들고 채우는 위치에 코드를 게시 할 수 있습니까? – yinkou

+1

질문을 업데이트했습니다 .. – Shri

0

원하는만큼 주석을 추가 할 수 있습니다. 그러나 각 주석의보기는 해당 주석의 coordinate 속성이지도보기의 보이는 부분과 교차 할 때까지 작성되지 않습니다. MapKit은지도에 주석을 추가했기 때문에보기를 만들지 않습니다.

+0

이 경우 조회수가 100을 초과 할 때만 그리지 않습니다. 101 회의 조회수를 제공하면 첫 번째 조회수는 여전히 조회 된 이전 조회수와 표시되는 부분입니다. 그러나 101 개의 화면으로 이동하자마자 아무 것도 표시되지 않습니다. 대의원조차 불리지 않는다. – Shri

관련 문제