我想在地图上使用不同颜色的图钉,例如一些图钉应该是红色的,一些图钉应该是绿色的,一些图钉应该是紫色的。
我正在使用下面的代码,在这段代码中,一次只会丢弃一个颜色引脚。
我想知道,我们可以在地图上同时放置不同颜色的图钉吗
-(void)showMap
{
    [map_View setZoomEnabled:YES];
    [map_View setScrollEnabled:YES];
    CLLocationCoordinate2D coordinate;
    coordinate.latitude = 49.2802;
    coordinate.longitude = -123.1182;
    map_View.region = MKCoordinateRegionMakeWithDistance(coordinate, 2000, 2000);
    // Set 10 random locations on the map for testing purposes
    //
    for(int i=0; i<10; i++) {
        CGFloat latDelta = rand()*.035/RAND_MAX -.02;
        CGFloat longDelta = rand()*.03/RAND_MAX -.015;
        CLLocationCoordinate2D newCoord = { coordinate.latitude + latDelta, coordinate.longitude + longDelta };
        RetailerAnnotation *ann = [[RetailerAnnotation alloc] initWithLocation:newCoord];
       // ann.coordinate = newCoord;
        //m_pinColor = @"BLUE";
        if(i< 4)
        {
        m_pinColor = @"RED";
        }
        else if(i>=4 && i<7)
        {
            m_pinColor = @"BLUE";
        }
        else if(i>=7 && i<10)
        {
        m_pinColor = @"GREEN";
        }
        NSLog(@"pin color:%@",m_pinColor);
        [ann setTitle:[NSString stringWithFormat:@"Title%d",i]];
        [ann setSubtitle:[NSString stringWithFormat:@"subTitle%d",i]];
        [map_View addAnnotation:ann];
        [ann release];
    }
}
- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
    static NSString *identifier = @"myPin";
    MKPinAnnotationView *pinView = nil;
    NSLog(@"pin color0:%@",m_pinColor);
    pinView = (MKPinAnnotationView *)[map_View dequeueReusableAnnotationViewWithIdentifier:identifier];
    if (pinView == nil)
    {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        pinView.canShowCallout = YES;
        pinView.animatesDrop = YES;
    /*
        if([m_pinColor isEqualToString:@"RED"]) {
            NSLog(@"pin color1:%@",m_pinColor);
            [pinView setPinColor:MKPinAnnotationColorPurple];
        }
        else if([m_pinColor isEqualToString:@"GREEN"]){
            NSLog(@"pin color2:%@",m_pinColor);
            [pinView setPinColor:MKPinAnnotationColorGreen];
        }
        else if([m_pinColor isEqualToString:@"BLUE"]){
            NSLog(@"pin color3:%@",m_pinColor);
            [pinView setPinColor:MKPinAnnotationColorRed];
        }*/
    }
    if([m_pinColor isEqualToString:@"RED"]) {
    NSLog(@"pin color1:%@",m_pinColor);
    [pinView setPinColor:MKPinAnnotationColorRed];
}
else if([m_pinColor isEqualToString:@"GREEN"]){
    NSLog(@"pin color2:%@",m_pinColor);
    [pinView setPinColor:MKPinAnnotationColorGreen];
}
else if([m_pinColor isEqualToString:@"BLUE"]){
    NSLog(@"pin color3:%@",m_pinColor);
    [pinView setPinColor:MKPinAnnotationColorPurple];
}
    return pinView;
    //[pinView release];
}