Desidero aggiungere un numero di annotazioni (intorno a 500) su una mappa ma il massimo che sembra essere visualizzato è 100. Se vado oltre 100, il metodo delegato viewForAnnotation non viene chiamato. Tuttavia funziona perfettamente per annotazioni indicati 100.Numero massimo di annotazioni (MKAnnotation) che è possibile tracciare su MKMapView?
ecco il codice: (funziona solo quando il contatore di annotationArray matrice è inferiore a 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];
Il metodo delegato è:
EDIT: Come per i commenti, ha iniziato riutilizzando la vista, ma senza fortuna :(
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;
Non sono riuscito a trovare alcuna restrizione nella documentazione o altrove. Potrebbe essere un problema di memoria?
Cosa succede se si aggiunge il primo oggetto in 'allPoints' 500 volte al' annotationArray'? –
E 'possibile fornire il codice sorgente per 'NVPolylineAnnotation'? –