I am using MKMapview in my i
MKAnnotation
)MKAnnotationView
)Make sure you define the title, background image, and other elements of your custom annotation in the AnnotationView
class as properties.
Override the following method, and set the values of the properties you defined in AnnotationView
class.
- (MKAnnotationView*) mapView:(MKMapView *)mapView viewForAnnotation:(id)annotation{
if ([
My custom annotation class was 'Annotation' and custom annotation view class was 'CustomAnnotation'. Change according to your needs.
After this, just create an object of the Annotation
class, and use it.
EDIT :
Make sure you override the follwing method int he custom annotation view class:
in .h:
- (id)initWithAnnotation:(id)annotation reuseIdentifier:(NSString *)reuseIdentifier;
in .m:
- (id)initWithAnnotation:(id)annotation reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
if (self) {
}
return self;
}
EDIT 2 :
You may use it in your view controller like this :
MKMapView* cellMap = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 290, 100)];
cellMap.delegate = self;
cellMap.userInteractionEnabled = NO;
CLLocationCoordinate2D center = CLLocationCoordinate2DMake();
MKCoordinateSpan span = MKCoordinateSpanMake(0.04, 0.04);
MKCoordinateRegion region = MKCoordinateRegionMake(center, span);
cellMap.showsUserLocation = NO;
[cellMap setRegion:region animated:YES];
Annotation* anon = [[Annotation alloc] init];
anon.coordinate = center;
[cellMap addAnnotation:anon];
[checkIn addSubview:cellMap];