0

我最近开始编程,我有一个问题!我创建了一个带有注释和披露按钮的地图视图。

如何使用披露按钮创建多个注释,点击后,根据注释选择转到不同的描述?

这是我的代码:

@synthesize mapView;

-(void)viewDidLoad {    

    [super viewDidLoad];
    [mapView setMapType:MKMapTypeHybrid];
    [mapView setZoomEnabled:YES];
    [mapView setScrollEnabled:YES];
    [mapView setDelegate:self];

    MKCoordinateRegion bigBen = { {0.0, 0.0} , {0.0, 0.0} };
    bigBen.center.latitude = 51.50063;
    bigBen.center.longitude = -0.124629;
    bigBen.span.longitudeDelta = 0.02f;
    bigBen.span.latitudeDelta = 0.02f;
    [mapView setRegion:bigBen animated:YES];

    Annotation *ann1 = [[Annotation alloc] init];
    ann1.title = @"Big Ben";
    ann1.subtitle = @"Your subtitle";
    ann1.coordinate = bigBen.center;
    [mapView addAnnotation: ann1];

    MKCoordinateRegion Bridge = { {0.0, 0.0} , {0.0, 0.0} };
    Bridge.center.latitude = 51.500809;
    Bridge.center.longitude = -0.120914;
    Bridge.span.longitudeDelta = 0.02f;
    Bridge.span.latitudeDelta = 0.02f;
    [mapView setRegion:Bridge animated:YES];

    Annotation *ann2 = [[Annotation alloc] init];
    ann2.title = @"Westminster Bridge";
    ann2.subtitle = @"Your subtitle";
    ann2.coordinate = Bridge.center;
    [mapView addAnnotation:ann2];

}

-(MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation {
    MKPinAnnotationView *MyPin=[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"current"];
    MyPin.pinColor = MKPinAnnotationColorPurple;

    UIButton *advertButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [advertButton addTarget:self action:@selector(button:) forControlEvents:UIControlEventTouchUpInside];

    MyPin.rightCalloutAccessoryView = advertButton;
    MyPin.draggable = NO;
    MyPin.highlighted = YES;
    MyPin.animatesDrop=TRUE;
    MyPin.canShowCallout = YES;

    return MyPin;
}
4

1 回答 1

0

通常的方法是-mapView:annotationView:calloutAccessoryControlTapped:在您的地图视图委托中实现。您可以使用 annotaionView 参数来决定点击了哪个注释以及要显示哪些信息。

于 2013-08-01T03:00:04.670 回答