我认为它对你的支持。你可以试试这个代码。你可以添加我的注释 .h 和 .m 文件并做一些更改我的注释
我的注释.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
@interface MyAnnotation : NSObject<MKAnnotation> {
CLLocationCoordinate2D coordinate;
NSString* title;
NSString* subtitle;
UIImage* image;
}
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString* title;
@property (nonatomic, copy) NSString* subtitle;
@property (nonatomic, retain) UIImage* image;
@end
my annotation.m
#import "MyAnnotation.h"
@implementation MyAnnotation
@synthesize title;
@synthesize subtitle;
@synthesize coordinate;
@synthesize image;
- (void)dealloc
{
[super dealloc];
self.title = nil;
self.subtitle = nil;
self.image=nil;
}
@end
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
//NSLog(@"welcome into the map view annotation");
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
// try to dequeue an existing pin view first
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier]autorelease];
//annotation.image = [UIImage imageNamed:@"shop-1.png"];
//[pinView setImage:[UIImage imageNamed:@"shop-1.png"]];
UIImageView *thumbnailImageView = [[UIImageView alloc] initWithImage:((MyAnnotation *)annotation).image];
CGRect newBounds = CGRectMake(0.0, 0.0, 32.0, 32.0);
[thumbnailImageView setBounds:newBounds];
pinView.leftCalloutAccessoryView = thumbnailImageView;
[thumbnailImageView release];
//UIImageView *profileIconView = [[UIImageView alloc] initWithImage:featuredDealcouponImage1];
// [pinView setImage:featuredDealcouponImage1];
pinView.animatesDrop=NO;
pinView.canShowCallout=YES;
pinView.pinColor=MKPinAnnotationColorGreen;
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
[rightButton addTarget:self action:@selector(_annotation_btn_click:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = rightButton;
return pinView;
}