美文网首页
百度地图点击自定义标记不显示泡泡但能做其他操作

百度地图点击自定义标记不显示泡泡但能做其他操作

作者: 谁在弹奏一曲东风破 | 来源:发表于2017-03-24 12:12 被阅读620次
    • 问题:
      如下图所示,在设计的时候在地图上添加标志,但是点击的效果是跳转,而不是显示泡泡动画,或者显示泡泡动画之后点击泡泡动画跳转
    1
    • 分析需求:
      1、往地图上添加自定义标志物
      2、标志物显示数据
      3、点击标志物不能显示泡泡,但是能实现其他的操作

    • 分布操作
      1、通过子类化<b>BMKAnnotationView</b>并重载<b>-initWithAnnotation:reuseIdentifier</b>将一个自定义的label添加自定义视图上,因为不能看是泡泡所以需要设置属性canShowCallout为No

    - (id)initWithAnnotation:(id<BMKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier{
        self  = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
        if (self) {
            self.backgroundColor = [UIColor clearColor];
            self.image = [UIImage imageNamed:@"map_Animate"];
            _countLbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 10, 30, 20)];
            _countLbl.textAlignment = NSTextAlignmentCenter;
            _countLbl.font = [UIFont systemFontOfSize:12];
            _countLbl.textColor = [UIColor whiteColor];
            _countLbl.backgroundColor = [UIColor clearColor];
            _countLbl.userInteractionEnabled = NO;
            [self addSubview:_countLbl];
            self.canShowCallout = NO;
        }
        return self;
    }
    

    2、子类化BMKPointAnnotation,并添加属性id

    /*
     *自定义Annotation
     */
    @interface CustomeAnnotation : BMKPointAnnotation
    @property (nonatomic, assign) NSUInteger releatedId;
    
    @end
    

    3、添加CustomeAnnotation的实例到mapview时,需要切记一定要设置title属性,具体原因是,如果不设置的话,

    - (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view
    

    此方法只会响应一次,title属性只会影响到泡泡,而我们设置了泡泡不现实,所以无论title属性设置为什么都不会影响到界面

    4、实现viewForAnnotation方法

    5、实现didSelectAnnotationView方法,在里面需要设置view.selected = NO

     - (void)mapView:(BMKMapView *)mapView didSelectAnnotationView:(BMKAnnotationView *)view{
        view.selected = NO;
        
       /**
        一些其他的操作,如跳转
        **/
    }
    

    补充:
    1、开启定位之后点击定位会弹出“ 我的位置”的泡泡,如果要不显示,可设置,userLocation.title= nil;

    相关文章

      网友评论

          本文标题:百度地图点击自定义标记不显示泡泡但能做其他操作

          本文链接:https://www.haomeiwen.com/subject/fwaxottx.html