我正在使用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
答案 0 :(得分: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_;
答案 1 :(得分:2)
在ViewDidLoad中设置委托