2013-06-17 4 views
-1

Я создаю пользовательскую аннотацию для отображения карты. Когда я размещаю булавку на карте, показывая аннотацию с помощью двух кнопок. Это работа для ios 6, но когда я тестирую этот код в ios 5, я не вижу никакой аннотации.MapKit аннотация IOS 5 не отображается

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id   <MKAnnotation>)annotation 
    { 

if ([annotation isKindOfClass:[MKUserLocation class]]) 
    return nil; //return nil to use default blue dot view 
NSLog(@"viewForAnnotation"); 
MKAnnotationView *annotationView = [[MKPinAnnotationView alloc] 

    initWithAnnotation:annotation reuseIdentifier:@"loc"]; 
annotationView.draggable = YES; 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 

    [button setTitle:@"Добавить" forState:(UIControlStateNormal)]; 

button.frame = CGRectMake(0, 0, 76, 23); 
if (plased == YES){ 
    annotationView.rightCalloutAccessoryView = button; 
} 

[button addTarget:self action:@selector(fixPoint:) forControlEvents:(UIControlEventTouchUpInside)]; 


UIButton *buttonLeft = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
[buttonLeft setTitle:@"Удалить" forState:(UIControlStateNormal)]; 
buttonLeft.frame = CGRectMake(0, 0, 66, 23); 
[buttonLeft addTarget:self action:@selector(cancelPoint:) forControlEvents:(UIControlEventTouchUpInside)]; 
if (plased == YES){ 
    annotationView.leftCalloutAccessoryView = buttonLeft; 
} 
annotationView.tag = [geoPointsList count]+1; 
annotationView.canShowCallout = YES; 

return annotationView; 
    } 

ответ

0

Я ставлю здесь Простой пример, как создавать собственные AnnotationView.

Создание пользовательских 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 

И в .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 

// Использование аннотаций Добавить #import "AnnotationView.h" в вашем соответствующем .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]; 
Смежные вопросы