Actualmente estoy agregando anotaciones a mi mapa a través de un bucle ... pero las anotaciones solo aparecen en mi mapa en grupos. Además, con carga, solo se muestran unas 4 anotaciones en el mapa ... pero a medida que muevo el mapa un poco, aparecen todas las anotaciones que deberían estar ahí.Vista de mapa - Anotaciones aparecen una a la vez
¿Cómo puedo obtener todas las anotaciones para que se carguen en el lugar correcto, de a una por vez?
¡Gracias de antemano!
Aquí está el código que estoy usando para añadir anotaciones:
NSString *incident;
for (incident in weekFeed) {
NSString *finalCoordinates = [[NSString alloc] initWithFormat:@"%@", [incident valueForKey:@"coordinates"]];
NSArray *coordinatesArray = [finalCoordinates componentsSeparatedByString:@","];
latcoord = (@"%@", [coordinatesArray objectAtIndex:0]);
longcoord = (@"%@", [coordinatesArray objectAtIndex:1]);
// Final Logs
NSLog(@"Coordinates in NSString: [%@] - [%@]", latcoord, longcoord);
CLLocationCoordinate2D coord;
coord.latitude = [latcoord doubleValue];
coord.longitude = [longcoord doubleValue];
DisplayMap *ann = [[DisplayMap alloc] init];
ann.title = [NSString stringWithFormat: @"%@", [incident valueForKey:@"incident_type"]];
ann.subtitle = [NSString stringWithFormat: @"%@", [incident valueForKey:@"note"]];
ann.coordinate = coord;
[mapView addAnnotation:ann];
[ann release];
}
// Custom Map Markers
-(MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation {
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil; //return nil to use default blue dot view
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil) {
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.canShowCallout = YES;
if ([annotationView.annotation.title isEqualToString:@"one"]) {
UIImage *pinImage = [UIImage imageNamed:@"marker_1.png"];
[annotationView setImage:pinImage];
}
if ([annotationView.annotation.title isEqualToString:@"two"]) {
UIImage *pinImage = [UIImage imageNamed:@"marker_2.png"];
[annotationView setImage:pinImage];
}
annotationView.annotation = annotation;
return annotationView;
}
- (void) mapView:(MKMapView *)mapV didAddAnnotationViews:(NSArray *)views {
CGRect visibleRect = [mapV annotationVisibleRect];
for (MKAnnotationView *view in views) {
CGRect endFrame = view.frame;
CGRect startFrame = endFrame; startFrame.origin.y = visibleRect.origin.y - startFrame.size.height;
view.frame = startFrame;
[UIView beginAnimations:@"drop" context:NULL];
[UIView setAnimationDuration:0.4];
view.frame = endFrame;
[UIView commitAnimations];
}
}
¿Podría publicar su código para agregar anotaciones? –
Acaba de agregarse. ¡Gracias! –
¡Gracias! ¿Podría publicar el método viewForAnnotation también? –