2012-05-08 2 views
0

У меня есть аннотация, установленная в моем mapview, используя приведенный ниже код. Проблема в том, что позиция аннотационного изображения неверна, она помещена справа от фактического местоположения, а не пятна, как при использовании обычных контактов.Ошибка пользовательской аннотации

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
     return nil; 
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier"; 
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier]; 
    if(annotationView) 
     return annotationView; 
    else 
    { 
     MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation 
                     reuseIdentifier:AnnotationIdentifier] autorelease]; 
     annotationView.canShowCallout = YES; 
     annotationView.image = [UIImage imageNamed:[NSString stringWithFormat:@"townhouse.png"]]; 
     UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]; 
     [rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside]; 
     [rightButton setTitle:annotation.title forState:UIControlStateNormal]; 
     annotationView.rightCalloutAccessoryView = rightButton; 
     annotationView.canShowCallout = YES; 
     annotationView.draggable = YES; 
     return annotationView; 
    } 
    return nil; 
} 

Любая помощь вообще была бы признательна!

/Marcus

ответ

1

Маркус,

использовать centerOffset свойство MKAnnotationView, чтобы переместить вид пользовательских аннотаций.

annotationView.centerOffset = CGPointMake(xOffset, yOffest);

+0

Thanks! Вот и все! :П – Marcus

Смежные вопросы