GMSMapViewDelegate方法不起作用

时间:2014-03-03 15:01:53

标签: ios objective-c google-maps

我是Objective-C的新手,我正在使用Google Maps SDK for iOS。 我想在单击标记时看到NSLog输出。我使用了以下GMSMapViewDelegate的委托方法:

  • -mapView:didTapMarker:
  • -mapView:didTapInfoWindowOfMarker: 但我没有看到任何有效的日志。

这是我的代码。您认为缺少什么?

#import "testViewController.h"

@interface testViewController ()

@end

@implementation testViewController{
    GMSMapView *mapView_;
}


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    mapView_.delegate = self;

    GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:41.12
                                                            longitude:29.05
                                                                 zoom:12];
    mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];
    mapView_.myLocationEnabled = YES;
    self.view = mapView_;


    GMSMarker *marker = [[GMSMarker alloc] init];
    marker.position = CLLocationCoordinate2DMake(41.12, 29.05);
    marker.title = @"burdayım";
    marker.map = mapView_;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
    NSLog(@"ssssss");
}



- (void)dealloc {
    [_V_map release];
    [super dealloc];
}
@end

1 个答案:

答案 0 :(得分:3)

您正在设置mapView_.delegate = self;在mapView_ = [GMSMapView mapWithFrame:self.view.bounds camera:camera];之前,当您设置委托时,mapView_将为nil;在instanciation之后设置委托,因此您的实例变量不是nil。