xcode:要映射的注释

时间:2014-07-28 16:11:59

标签: xcode map annotations

我的应用是以正确的方式显示地图,但是注释(我选择的地方的引脚)没有显示......为什么?

- (void)viewDidLoad{
[super viewDidLoad];
CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = 45.40170;
zoomLocation.longitude = 8.91552;
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, METERS_PER_MILE, METERS_PER_MILE);
[_mappa setRegion:viewRegion animated:YES];
[_mappa regionThatFits:viewRegion];
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = zoomLocation;
point.title = @"TITLE";
point.subtitle = @"SUBTITLE";
[_mappa addAnnotation:point];
}

抱歉,我是xcode的新手,对于智能手机,我只在Android上开发

1 个答案:

答案 0 :(得分:0)

您的代码似乎正确地将注释添加到MKMapView,但您需要通过在视图控制器中实现委托方法mapView:viewForAnnotation:来为注释提供注释视图,如下所示:

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

static NSString *identifier = @"MyLocation";

    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;
}

假设您正在使用界面构建器,请确保将MKMapView的委托设置为视图控制器。