UIMapView中的引脚和引脚颜色失败

时间:2011-12-09 20:23:14

标签: xcode mkmapview

我在MapView上遇到了一些问题。

首先,无论我如何设置引脚的颜色,它都保持红色。

其次,没有掉针的动画,该引脚只与UIView一起出现

这是我的代码。

非常感谢你。

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {

    self->mapView.mapType = MKMapTypeHybrid;
    CLLocationCoordinate2D center;
    center.latitude = 33.79518;
    center.longitude = 130.92263;

    //declare span of map (height and width in degrees)
    MKCoordinateSpan span;
    span.latitudeDelta = .05;
    span.longitudeDelta = .01;

    //add center and span to a region, 
    //adjust the region to fit in the mapview 
    //and assign to mapview region
    MKCoordinateRegion region;
    region.center = center;
    region.span = span;
    mapView.region = [mapView regionThatFits:region];
    transportfu *addAnnotation = [[transportfu alloc] initWithCoordinate:center];
    [addAnnotation setTitle:@"City"];  
    [addAnnotation setSubTitle:@"Fukuoka"];  

    [mapView addAnnotation:addAnnotation];  
    [super viewDidLoad];
    mapView.showsUserLocation = YES;
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation{  
    MKPinAnnotationView *annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];  

    annView.canShowCallout = YES;  
    [annView setSelected:YES];  
    annView.pinColor = MKPinAnnotationColorGreen;  
    annView.calloutOffset = CGPointMake(-5, 5);  
    annView.animatesDrop=YES;  
    return annView;       
}  

1 个答案:

答案 0 :(得分:1)

您的viewForAnnotation方法需要一种出列方法。

试试这个:

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{  
    static NSString *MyAnnotationIdentifier = @"MyPin";
    MKPinAnnotationView *annView =
    (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:MyAnnotationIdentifier];
    if (!annView)
    {
        annView=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"MyPin"];  

        annView.canShowCallout = YES;  
        [annView setSelected:YES];  
        annView.pinColor = MKPinAnnotationColorGreen;  
        annView.calloutOffset = CGPointMake(-5, 5);  
        annView.animatesDrop=YES;  
    } else {
        annView.annotation = annotation;
    }
    return annView;       
}