简体   繁体   English

Xcode 4.3.3 Mapview,注释未显示

[英]Xcode 4.3.3 Mapview, annotation not showing

My annotation (homeMark) are not showing in mapView. 我的注释(homeMark)没有显示在mapView中。 I have made my viewController delegate in IB 我已经在IB中创建了viewController委托

For some reason in the delegate method if ([annotation isKindOfClass:[HomeMark class]]) { 由于某种原因,在委托方法中if([annotation isKindOfClass:[HomeMark class]]){

Fails.....Annotation is not part of "Homemark" class... 失败.....注释不是“ Homemark”类的一部分...

What am i doing wrong ? 我究竟做错了什么 ?

code... 码...

- (IBAction)clubHouse:(id)sender{
    MKCoordinateRegion region = { {0.0, 0.0 } , {0.0,0.0} };
    region.center.latitude = 55.305858;
    region.center.longitude = 12.386036;


    CLLocationCoordinate2D coord = {
        .latitude = region.center.latitude, 
        .longitude = region.span.longitudeDelta};

    HomeMark *homeMark = [[HomeMark alloc] 
                          initWithCoordinate:coord 
                          andMarkTitle:@"Klubhus" 
                          andMarkSubTitle:@"Stevns Cykel Motion"];

    [mapMyView addAnnotation:homeMark];

    [mapMyView setMapType:MKMapTypeStandard];
    [mapMyView setZoomEnabled:YES];
    [mapMyView setScrollEnabled:YES];
    region.span.longitudeDelta = 0.007f;
    region.span.latitudeDelta = 0.007f;
    [mapMyView setRegion:region animated:YES];
    //[mapMyView setDelegate:sender];    
    mapMyView.showsUserLocation = YES;

}

And the ViewForAnnotation. 还有ViewForAnnotation。

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

    static NSString *identifier = @"MyLocation";
    if ([annotation isKindOfClass:[HomeMark class]]) {

        MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
        if (annotationView == nil) {
            annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        }
        else {
            annotationView.annotation = annotation;
        }

        annotationView.enabled = YES;
        annotationView.canShowCallout = YES;

        return annotationView;
    }

    return nil; 
}

It looks like you are specifying the coordinates incorrectly so that the annotation is not where you expect. 看起来您指定的坐标不正确,因此注释不在您期望的位置。

Instead of this: 代替这个:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.span.longitudeDelta};  // <-- span doesn't make sense

try this: 尝试这个:

CLLocationCoordinate2D coord = {
    .latitude = region.center.latitude, 
    .longitude = region.center.longitude};  // <-- not span

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM