首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我想根据照片来绘制MKmapannotation

我想根据照片来绘制MKmapannotation
EN

Stack Overflow用户
提问于 2014-04-03 10:19:37
回答 1查看 54关注 0票数 1

下面是我的代码:

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

    MapLocation *Annotation = annotation;

    static NSString *identifier = @"MapLocation";

    if ([annotation isKindOfClass:[MapLocation class]]) {

    MKPinAnnotationView *annotationViewBus = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    MKPinAnnotationView *annotationViewTaxi = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    MKPinAnnotationView *annotationViewSam = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];
    MKPinAnnotationView *annotationViewMetro = (MKPinAnnotationView *) [self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    //bus
    if (!annotationViewBus ) {
        annotationViewBus = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        annotationViewBus.enabled = YES;
        annotationViewBus.canShowCallout = YES;

        if (busStatus==YES) {
            annotationViewBus.image=[UIImage imageNamed:@"annotationBus.png"];//here we use a nice image instead of the default pins
        return annotationViewBus;

        }else {
        annotationViewBus.annotation = annotation;

        }

    }


    //taxi
    if (!annotationViewTaxi ) {
        annotationViewTaxi = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        annotationViewTaxi.enabled = YES;
        annotationViewTaxi.canShowCallout = YES;

        if (taxiStatus==YES) {
            annotationViewTaxi.image=[UIImage imageNamed:@"annotationTaxi.png"];//here we use a nice image instead of the default pins
          //  return annotationViewTaxi;

        }else {
        annotationViewTaxi.annotation = annotation;
        }

    }


    //sam
    if (!annotationViewSam ) {
            annotationViewSam = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationViewSam.enabled = YES;
            annotationViewSam.canShowCallout = YES;

            if(samStatus==YES){
                annotationViewSam.image=[UIImage imageNamed:@"annotationSam.png"];
                UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
                [rightButton setTitle:[Annotation name] forState:UIControlStateNormal];
                [rightButton addTarget:self action:@selector(chatButtonPressed:) forControlEvents:UIControlEventTouchUpInside]; //display another view
                annotationViewSam.rightCalloutAccessoryView = rightButton;
               // return annotationViewSam;

            }else {
                annotationViewSam.annotation = annotation;
            }

        }


    //metro
    if (!annotationViewMetro ) {
                annotationViewMetro = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
                annotationViewMetro.enabled = YES;
                annotationViewMetro.canShowCallout = YES;

                if(metroStatus==YES){
                    annotationViewMetro.image=[UIImage imageNamed:@"annotationMetro.png"];

                }else {
                    annotationViewMetro.annotation = annotation;
                }
        //return annotationViewMetro;


        }


}
return nil;

}

EN

回答 1

Stack Overflow用户

发布于 2014-04-03 12:33:06

您忘记了每个注释视图类型的return (MKAnnotationView *)。只需为每个类型添加返回AnnotationView即可。例如:

//metro

代码语言:javascript
运行
复制
if (!annotationViewMetro ) {
            annotationViewMetro = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
            annotationViewMetro.enabled = YES;
            annotationViewMetro.canShowCallout = YES;

            if(metroStatus==YES){
                annotationViewMetro.image=[UIImage imageNamed:@"annotationMetro.png"];

            }else {
                annotationViewMetro.annotation = annotation;
            }

只需取消对此行的注释:

代码语言:javascript
运行
复制
    return annotationViewMetro;

    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22826647

复制
相关文章

相似问题

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