2011-12-09 7 views
0

MapViewで少し問題があります。UIMapViewでドロップピンとピンの色が正しくありません

まず、どのようにピンの色を設定しても、赤色のままです。

第二に、ドロップピンのないアニメーションが存在しない、ピンはちょうどここに私のコードです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

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;  
} 
+0

感謝を!それは今働いている! – Clarence

関連する問題