3

我正在使用 Google Maps iOS API。没有一个委托方法被触发。我如何让它们工作?

MapViewController.h:

@interface MapViewController : UIViewController <GMSMapViewDelegate>
@property (strong, nonatomic) IBOutlet GMSMapView *mapView_;

@end

#import "MapViewController.h"
#import <GoogleMaps/GoogleMaps.h>
@interface MapViewController ()

@end

MapViewController.m @implementation MapViewController @synthesize mapView_; GMSCircle *circ;

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

- (void)viewDidLoad
{
[super viewDidLoad];

// Do any additional setup after loading the view.
}

- (void)loadView {
mapView_.delegate = self;

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10
                                                        longitude:10
                                                             zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
self.view = mapView_;

mapView_.mapType = kGMSTypeHybrid;

CLLocationCoordinate2D circleCenter = CLLocationCoordinate2DMake(10, 10);
GMSCircle *circ = [GMSCircle circleWithPosition:circleCenter
                                         radius:10];
circ.tappable = true;
[circ setFillColor:[UIColor colorWithRed:1 green:0 blue:0 alpha:.5]];

circ.map = self.mapView_;

}

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

- (void)mapView:(GMSMapView *)mapView didTapOverlay:(GMSOverlay *)overlay
{
NSLog(@"in didTapOverlay");

[overlay isKindOfClass:[circ class]];
if ([overlay isKindOfClass:[circ class]]) {
        GMSMarker *marker = [[GMSMarker alloc] init];
        marker.position = CLLocationCoordinate2DMake(10, 10);
        marker.title = @"Place";
        marker.snippet = @"Sub Place";
        marker.map = mapView_;

}
}


- (void) mapView:(GMSMapView *) mapView willMove:(BOOL) gesture
{
NSLog(@"In willMove");
}
@end
4

2 回答 2

8

我认为您将委托属性设置为早期

试试这个 :

GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:10
                                                        longitude:10
                                                             zoom:15];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
mapView_.myLocationEnabled = YES;
mapView_.delegate = self;
self.view = mapView_;
于 2013-08-01T16:17:32.153 回答
2

在 ViewDidLoad 中设置委托

于 2013-08-10T04:13:01.573 回答