针脚数组,颜色不变

时间:2013-11-27 15:21:04

标签: ios objective-c arrays annotations mapkit

我正在尝试动态设置属于不同类的这两个点的引脚颜色,但它们在我的地图上不显示不同的颜色。你在我的阵列的for循环中看到任何问题吗?

#define UNIVERSITY_LATITUDE 35.22836;
#define UNIVERSITY_LONGITUDE 126.84784;
#define HOTEL_LATITUDE 34.55;
#define HOTEL_LONGITUDE 127.36;


@implementation MapKitViewController


//Synthesize the getters and setters of the map view
@synthesize mapView;



- (void)viewDidLoad
{
    [super viewDidLoad];

    NSMutableArray *annotations = [[NSMutableArray alloc] init];
    CLLocationCoordinate2D location;

   //used to test Annotations of map, will be replaced by for loop to insert new points
    PhotoPoint *photoAnn;
    photoAnn = [[PhotoPoint alloc] init];
    location.latitude =UNIVERSITY_LATITUDE;
    location.longitude = UNIVERSITY_LONGITUDE;
    photoAnn.coordinate = location;
    [photoAnn setTitle:@"GIST"];
    [photoAnn setSubtitle:@"University"];
    [photoAnn setAnnotationType:@"Photo"];
    [annotations addObject:photoAnn];

    CommercialPoint *commAnn;
    commAnn = [[CommercialPoint alloc] init];
    location.latitude =HOTEL_LATITUDE;
    location.longitude = HOTEL_LONGITUDE;
    commAnn.coordinate = location;
    [commAnn setTitle:@"Hotel"];
    [commAnn setSubtitle:@"Hotel Center"];
    [commAnn setAnnotationType:@"Commercial"];
    [annotations addObject:commAnn];

    for (id eachObject in annotations){
        if ([eachObject isKindOfClass:[PhotoPoint class]])
        {
            photoAnn.pinColor = MKPinAnnotationColorGreen;
        }
        if ([eachObject isKindOfClass:[CommercialPoint class]])
        {
            commAnn.pinColor = MKPinAnnotationColorPurple;
        }

    //send the delgate messages to the mapview
    mapView.delegate = self;
    [self.mapView addAnnotations:annotations];

0 个答案:

没有答案