我的地图需要显示“Venues”和“BLUE”在附近和周围的“Parking Lots”。
The problem is that both pins show up in the same color.
该守则如下:
我的温和派认为:
#import <MapKit/MapKit.h>
@interface mapPinAnnotation : NSObject <MKAnnotation> {
NSString *title;
NSString *subtitle;
NSString *pinType; // this string will be set to either "Venue" or "Parking"
CLLocationCoordinate2D coordinate;
}
@property (nonatomic, retain) NSString *title, *subtitle;
@property (nonatomic) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *pinType;
@end
执行:
#import "mapPinAnnotation.h"
@implementation mapPinAnnotation
@synthesize coordinate;
@synthesize pinType;
@synthesize title, subtitle;
-(id) initWithCoordinate: (CLLocationCoordinate2D) c {
coordinate = c;
return self;
}
@end
这里指的是确定“表象”的方法——我注意到我使用一个“表象”变量——在全球宣布——因此,我可以把这个词推到“概览”方法中,但我认为,问题是:
-(void) dropThePin {
CLLocationCoordinate2D location = mapView.userLocation.coordinate;
location.latitude = latitude;
location.longitude = longitude;
if(pinAnnotation != nil) {
[mapView removeAnnotation:pinAnnotation];
[pinAnnotation release];
pinAnnotation = nil;
}
// Create (alloc/init) a Pin, set its Title & Subtitle, and add/place it:
pinAnnotation = [[mapPinAnnotation alloc] initWithCoordinate:location];
pinAnnotation.pinType = @"VENUE";
tempPin = pinAnnotation;
[pinAnnotation setTitle: @"Some Stadium"];
[pinAnnotation setSubtitle: @"123 Main St."];
[mapView addAnnotation:pinAnnotation];
// Set-Up of 2nd. Pin:
location.latitude = 12.34567;
location.longitude = -23.45678;
pinAnnotation.pinType = @"PARKING";
if(parkingLotPin != nil) {
[mapView removeAnnotation:parkingLotPin];
[parkingLotPin release];
parkingLotPin = nil;
}
// Create (alloc/init) a Pin, set its Title & Subtitle, and add/place it:
parkingLotPin = [[mapPinAnnotation alloc] initWithCoordinate:location];
tempPin = pinAnnotation;
[parkingLotPin setTitle: @"Another Venue"];
[parkingLotPin setSubtitle: @"789 S. Broad Street"];
[mapView addAnnotation:parkingLotPin];
[parkingLotPin release];
}
最后,这里是“观点”方法:
-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation {
MKPinAnnotationView *thePin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
if (tempPin.pinType == @"VENUE") {
thePin.pinColor = MKPinAnnotationColorGreen;
NSLog(@"pin-type = %@", tempPin.pinType);
} else {
thePin.pinColor = MKPinAnnotationColorPurple;
NSLog(@"pin-type = %@", tempPin.pinType);
}
thePin.animatesDrop=TRUE;
thePin.canShowCallout = YES;
thePin.calloutOffset = CGPointMake(-5, 5);
return thePin;
}
问题在于,这两种颜色都有相同的颜色。
任何建议?