Creating custom pins for iPhone Mapkit
I am trying something a little different.
Instead of a class, I have used MKPinAnnotationView
and the inherited image instance. Here is the code for viewForAnnotation
. But it doesn't work. Nothing shows at all.
I also tried it using MKAnnotationView
and I get the same result.
- (MKAnnotationView *)mapView:(MKMapView *)eMapView viewForAnnotation:(id <MKAnnotation>)annotation {
int postTag = 0;
MKAnnotationView *pinView = (MKAnnotationView*)[eMapView dequeueReusableAnnotationViewWithIdentifier:@"Pin"];
if(pinView == nil) {
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"Pin"];
pinView.frame = CGRectMake(0, 0, 25, 25);
} else {
pinView.annotation = annotation;
}
pinView.image = [UIImage alloc];
NSString *data_annotation = [annotation getData];
if([data_annotation length] == 0) {
pinView.image = [UIImage imageNamed:@"pinYellow.png"];
// pinView.pinColor = MKPinAnnotationColorGreen;
}
else if(([[data_annotation rangeOfString:@"GRAY"].location != NSNotFound)){
pinView.image = [UIImage imageNamed:@"pinGray.png"];
// pinView.pinColor = MKPinAnnotationColorPurple;
}
els开发者_运维技巧e {
pinView.image = [UIImage imageNamed:@"pinRed.png"];
// pinView.pinColor = MKPinAnnotationColorRed;
}
// Set up the Right callout
UIButton *myDetailButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
myDetailButton.frame = CGRectMake(0, 0, 23, 23);
myDetailButton.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
myDetailButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
[myDetailButton addTarget:self action:@selector(checkButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
// Identify which pin is being selected
if ([[annotation title] isEqualToString:@"Current Location"]) {
postTag = 99999;
} else {
postTag = [annotation getPinID];
}
myDetailButton.tag = postTag;
pinView.rightCalloutAccessoryView = myDetailButton;
//pinView.animatesDrop = YES;
// Set to show a callout on the pin
pinView.canShowCallout = YES;
return pinView;
}
精彩评论