Mapkit用户位置针对附近医院的注释信息

时间:2014-02-19 13:20:45

标签: ios mapkit mkannotationview

我需要在自定义视图中显示医院详细信息。当我点击注释引脚时,它会在自定义视图中显示地址,但每当点击另一个引脚时,它会在自定义视图中显示相同的地址。我尝试了以下代码。提前致谢。

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view      calloutAccessoryControlTapped:(UIControl *)control
{
    name=[place objectForKey:@"name"];
    vicinity =[place objectForKey:@"vicinity"];


    self.myModalView = [[UIView alloc] initWithFrame:CGRectMake(0, 59, 320, 300)] ;

    [self.view addSubview:self.myModalView];
    [self.myModalView setBackgroundColor:[UIColor whiteColor]];
    [self.myModalView setBackgroundColor:[UIColor redColor]];
    self.btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.btn addTarget:self
                  action:@selector(back:)
        forControlEvents:UIControlEventTouchUpInside];
    [self.btn setTitle:@"Dismiss" forState:UIControlStateNormal];
    self.btn.frame = CGRectMake(0, 30, 80, 30);
    [self.myModalView addSubview:self.btn];

    _lblName=[[UILabel alloc]initWithFrame:CGRectMake(20, 120, 280, 60)];
    self.lblName.numberOfLines=5;

    self.lblName.text=name;
    NSLog(@"%@",self.lblName.text);
    [self.myModalView addSubview:_lblName];

    _lblDes=[[UILabel alloc]initWithFrame:CGRectMake(20, 200, 280, 80)];
    self.lblDes.numberOfLines=5;
    self.lblDes.text=vicinity;
    [self.myModalView addSubview:_lblDes];

}

1 个答案:

答案 0 :(得分:0)

您应该使用它来自定义annotationView:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation

并使用标注:

@property (retain, nonatomic) UIView *rightCalloutAccessoryView;
@property (retain, nonatomic) UIView *leftCalloutAccessoryView;

希望有所帮助

相关问题