iOS 自定义百度地图大头针点击事件

来源:互联网 发布:淘宝商城男士运动套装 编辑:程序博客网 时间:2024/04/30 15:00


UMKPointAnnotation* pointAnnotation = [[UMKPointAnnotation alloc]init];


CLLocationCoordinate2D coor1;
                                coor1.latitude = baiduModel.latitude;
                                coor1.longitude = baiduModel.longitude;
                                pointAnnotation.voucherType = UMKVoucherCoupon ;
                                pointAnnotation.coordinate = coor1;
                                pointAnnotation.couponID = baiduModel.couponID;
                                pointAnnotation.title = baiduModel.businessName;
                                

                                [arr addObject:pointAnnotation];


[_mapView addAnnotations:arr] ;


- (BMKAnnotationView *)mapView:(BMKMapView *)mapView viewForAnnotation:(id<BMKAnnotation>)annotation
{
    NSString *identifier = @"baidu";
    BMKPinAnnotationView *annotationView = nil;
    if (!annotationView) {
        annotationView = [[BMKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
        btn.frame = CGRectMake(0, 0,annotationView.image.size.width, annotationView.image.size.height);
        [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        annotationView.enabled = YES;
        annotationView.userInteractionEnabled = YES;

       //如果想传值,我们可以这样

       UMKPointAnnotation *ffff = annotation;
        btn.tag = ffff.couponID;


        [annotationView addSubview:btn];
    },
    return annotationView;
}


-(void)btnAction:(UIButton *)sender

{

//这样就可以输出你想要传的ID值了

}

0 0