百度地图自定义大头针图片和添加标注

来源:互联网 发布:云之家软件 编辑:程序博客网 时间:2024/05/16 12:05

// 根据anntation生成对应的View

- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id <BMKAnnotation>)annotation

{ 

    NSString * AnnotationViewID = [NSString stringWithFormat:@"renameMark%d",map_i];

    

    newAnnotation = [[BMKPinAnnotationView allocinitWithAnnotation:annotation reuseIdentifier:AnnotationViewID];

    // 设置颜色

    ((BMKPinAnnotationView *)newAnnotation).pinColor = BMKPinAnnotationColorPurple;

    // 从天上掉下效果

    ((BMKPinAnnotationView *)newAnnotation).animatesDrop = NO;

    // 设置可拖拽

    ((BMKPinAnnotationView *)newAnnotation).draggable = YES;

    //设置大头针图标

    ((BMKPinAnnotationView *)newAnnotation).image = [UIImage imageNamed:@"icon"];

    

    UIView * popView = [[UIView alloc]initWithFrame:CGRectMake(0010053)];

    //设置弹出气泡图片

    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"yuanju_gnnr_icon"]];

    image.frame = CGRectMake(0010060);

    [popView addSubview:image];

    //自定义显示的内容

    UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(10710011)];

    label.text = @"医院";

    label.backgroundColor = [UIColor clearColor];

    label.font = [UIFont systemFontOfSize:11];

    label.textColor = [self hexStringToColor:@"#333333"];

    label.textAlignment = NSTextAlignmentLeft;

    [popView addSubview:label];

    

    UILabel * locationLabel = [[UILabel alloc]initWithFrame:CGRectMake(102510018)];

    locationLabel.text = [self.userDefaults objectForKey:@"loc"];

    locationLabel.backgroundColor = [UIColor clearColor];

    locationLabel.font = [UIFont systemFontOfSize:18];

    locationLabel.textColor = [self hexStringToColor:@"#333333"];

    locationLabel.textAlignment = NSTextAlignmentLeft;

    [popView addSubview:locationLabel];

    //根据获取到的地址来重新设置气泡的大小

    //地址标签

    CGRect locationRect = locationLabel.frame;

    locationRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width;

    locationLabel.frame = locationRect;

    //view宽度

    CGRect popRect = popView.frame;

    popRect.size.width = [locationLabel sizeThatFits:CGSizeZero].width + 20;

    popView.frame = popRect;

    //设置弹出气泡图片

    image.frame = popView.frame;

    

    BMKActionPaopaoView * pView = [[BMKActionPaopaoView alloc]initWithCustomView:popView];

    pView.frame = CGRectMake(0010060);

    ((BMKPinAnnotationView *)newAnnotation).paopaoView = nil;

    ((BMKPinAnnotationView *)newAnnotation).paopaoView = pView;

    map_i++;

    return newAnnotation;

    

}

0 0
原创粉丝点击