MKMapView多个注释调用按钮来详细查看

时间:2011-06-18 08:51:12

标签: ios objective-c mapkit

我正在开发一个用于本地搜索的应用程序,如餐馆等,通过使用这个应用程序http://www.totagogo.com/2011/02/08/google-local-search-ios-code/,我结构应用按钮来调出注释,通过导航到另一个detailViewController来提取细节。请通过提供一些教程/示例代码来帮助我克服这个问题。

1 个答案:

答案 0 :(得分:0)

我得到了解决方案

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(GoogleLocalObject *) annotation 
{

    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";


    MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc]
                                           initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
    customPinView.pinColor = MKPinAnnotationColorRed;
    customPinView.animatesDrop = YES;
    customPinView.canShowCallout = YES;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton addTarget:self
                    action:@selector(showDetails:)
          forControlEvents:UIControlEventTouchUpInside];
    customPinView.rightCalloutAccessoryView = rightButton;

    UIImageView *memorialIcon = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"googlemaps_pin.png"]];
    customPinView.leftCalloutAccessoryView = memorialIcon;
    [memorialIcon release];

    return customPinView;


}

- (void)showDetails:(id)sender {
    GoogleLocalObject *obj;
    for (int i = 0; i < [objectsFromGoogle count]; i++) {
        obj = [objectsFromGoogle objectAtIndex:i];
    }

    self.reverseGeocoder =
    [[[MKReverseGeocoder alloc] initWithCoordinate:obj.coordinate] autorelease];
    reverseGeocoder.delegate = self;
    [reverseGeocoder start];
}