在我的应用程序中,我通过显示计数来使用簇引脚机制,如果引脚上的计数大于1,我使用一种类型的图像'groupPin.png',如果它等于1 i使用另一个图像'singlePin.png',当从一个缩放级别更改为其他缩放级别时,地图视图没有显示确切的图像,它显示了组图像'groupIn.png',其中包含另一个簇的引脚数上一个缩放级别而不是图像'singlePin.png'。从一个缩放级别转到另一个缩放级别时,它会发生很多次。我不知道为什么引脚会像这样更新。 我发布了在地图视图上添加引脚的代码。请告诉我这种行为的解决方案。
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
if([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if(![annotation isKindOfClass:[CustomAnnotation class]])
return nil;
MKAnnotationView *pin = (MKAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"annotationPin"];
if (pin == nil)
{
pin = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotationPin"] autorelease];
}
NSString *status = ((CustomAnnotation*).annotation).subtitle;
if([status isEqualToString:@"grouping"])
{
// image with count on it.
UIImage *image = [UIImage imageNamed:@"groupPin.png"];
pin.image = countImage;
}
else
{
pin.image = [UIImage imageNamed:@"singlePin.png"];
pin.canShowCallout = YES;
}
return pin;
}
//将引脚添加到地图视图
- (void) addAnnotationPinsToCurrentRegion:(NSArray*) customPins
{
CustomAnnotation *annotation = nil;
NSMutableArray *customAnnotations = [[NSMutableArray alloc] init];
if([mapView.annotations count] != 0)
{
NSMutableArray *removedAnnotations = [[NSMutableArray alloc] initWithArray: mapView.annotations];
[removedAnnotations removeObject: mapView.userLocation];
[mapView removeAnnotations: removedAnnotations];
[removedAnnotations release];
}
for (NSDictionary *dictionary in customPins)
{
int count = [[dictionary objectForKey:@"CUSTOMCOUNT"]intValue];
float latitude = [[dictionary objectForKey:@"LATITUDE"]floatValue];
float longitude = [[dictionary objectForKey:@"LONGITUDE"]floatValue];
CLLocationCoordinate2D = CLLocationCoordinate2DMake(latitude, longitude);
if(count > 1)
{
annotation = [[CustomAnnotation alloc] initWithCoordinate:locationCoordinate];
annotation.title = @"title";
annotation.subtitle = @"grouping";
annotation.count = count;
}
else
if(count == 1)
{
annotation = [[CustomAnnotation alloc] initWithCoordinate:locationCoordinate];
annotation.title = [dictionary objectForKey:@"TITLE"];
annotation.subtitle = [dictionary objectForKey:@"SUBTITLE"];
}
[customAnnotations addObject:annotation];
[annotation release];
}
[mapView addAnnotations:customAnnotations];
[customAnnotations release];
}