This is Simple Example For how to Create Custom AnnotationView.
Create custom AnnotationView
:
#import <MapKit/MapKit.h>
@interface AnnotationView : MKPlacemark
@property (nonatomic, readwrite, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, strong) NSString *title;
@property (nonatomic, strong) NSString *subtitle;
// you can put here any controllers that you want. (such like UIImage, UIView,...etc)
@end
And in .m file
#import "AnnotationView.h"
@implementation AnnotationView
- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate addressDictionary:(NSDictionary *)addressDictionary
{
if ((self = [super initWithCoordinate:coordinate addressDictionary:addressDictionary]))
{
self.coordinate = coordinate;
}
return self;
}
@end
// Use Annotation Add #import "AnnotationView.h"
in your relevant .m file
:
CLLocationCoordinate2D pCoordinate ;
pCoordinate.latitude = LatValue;
pCoordinate.longitude = LanValue;
// Create Obj Of AnnotationView class
AnnotationView *annotation = [[AnnotationView alloc] initWithCoordinate:pCoordinate addressDictionary:nil] ;
annotation.title = @"I m Here";
annotation.subtitle = @"This is Sub Tiitle";
[self.mapView addAnnotation:annotation];
Above is simple Example of how to create AnnotationView
.