首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MKPointAnnotation不工作

MKPointAnnotation不工作
EN

Stack Overflow用户
提问于 2013-05-14 07:41:39
回答 1查看 645关注 0票数 1

你好,我得到了这个方法:

代码语言:javascript
复制
-(void)adresseZeigen
{
    NSLog(@"%s",__PRETTY_FUNCTION__);

    selectedAnnotation = [[MKPointAnnotation alloc]init];

    selectedAnnotation.title = selectedCompanyName;
    selectedAnnotation.subtitle = selectedCompanyAdresse;
    selectedAnnotation.coordinate = selectedCompanyPoint;


    NSLog(@"selected title: %@",selectedAnnotation.title);
    NSLog(@"selected subtitle: %@",selectedAnnotation.subtitle);
    NSLog(@"selected latitude is: %f", self.selectedAnnotation.coordinate.latitude );
    NSLog(@"selected longitude is: %f", self.selectedAnnotation.coordinate.longitude );

    [mapView addAnnotation:selectedAnnotation];

    MKCoordinateRegion selectedRegion;

    selectedRegion.center = selectedCompanyPoint;
    selectedRegion.span.longitudeDelta = 0.01;
    selectedRegion.span.latitudeDelta = 0.01;
    [mapView setRegion:selectedRegion animated:YES];

}

它实际上应该在我的mapview中给我一个注释。

我的日志输出是:

代码语言:javascript
复制
-[SecondViewController adresseZeigen]
selected title: Company 2
selected subtitle: Company 2 Adresse
selected latitude is: 48.620000
selected longitude is: 9.460000

但不知何故,我在地图上得不到注解。

有人能帮帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2013-05-14 16:24:43

仅此一项并不能为您提供地图上的任何实际注释视图。为了在地图中拥有注释视图,您需要为视图控制器声明MKMapViewDelegate,将其声明为您的mapview委托并实现该方法:

代码语言:javascript
复制
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation

这是为地图视图实际生成注释视图的方法。在您的例子中,您可能希望为MKPointAnnotation使用MKPinAnnotationView

您可以查看协议参考here

EDIT:该方法的示例实现(假设您的所有MKPointAnnotations都有相同的用途)可以是:

代码语言:javascript
复制
-(MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
    static NSString *reuseId = @"MyReuseID";
    MKPinAnnotationView * view = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:reuseId];
    if (!view) {
        view = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId];
        //custom setup of your view, such as
        //view.canShowCallout = YES;
    }
    return view;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16532896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档