GMSPolygon不';无法在iOS谷歌地图应用程序中工作

GMSPolygon不';无法在iOS谷歌地图应用程序中工作,ios,objective-c,xcode,google-maps,Ios,Objective C,Xcode,Google Maps,下面是我新的iOS谷歌地图应用程序的代码。我可以在用户点击屏幕时在地图上创建动态标记,但是标记之间的多边形形状不会被绘制出来。你知道为什么会这样吗 - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. //Controls whether the My Location dot and accuracy circle is enabled. CGFloat cur

下面是我新的iOS谷歌地图应用程序的代码。我可以在用户点击屏幕时在地图上创建动态标记,但是标记之间的多边形形状不会被绘制出来。你知道为什么会这样吗

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
//Controls whether the My Location dot and accuracy circle is enabled.
CGFloat currentZoom = 14.0f;
self.mapView.myLocationEnabled = YES;

//adds type of map: kGMSTypeSatellite, kGMSTypeTerrain, kGMSTypeHybrid, kGMSTypeNormal
self.mapView.mapType = kGMSTypeHybrid;

//Shows the compass button on the map
self.mapView.settings.compassButton = YES;

//Shows the my location button on the map
self.mapView.settings.myLocationButton = YES;

//Sets the view controller to be the GMSMapView delegate
self.mapView.delegate = self;
GMSCameraPosition *manhattan = [GMSCameraPosition cameraWithLatitude:40.790278
                                                        longitude:-73.959722
                                                             zoom:14];
self.mapView.camera = manhattan;
}
 //setting up zoom
-(void)ZoominOutMap:(CGFloat)level
{
self.mapView.delegate = self;
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.790218 longitude:-73.959722
                                                             zoom:level];
self.mapView.camera = camera;
}

-(void)zoomInMapView:(id)sender
{
CGFloat currentZoom;
currentZoom = currentZoom + 1;

[self ZoominOutMap:currentZoom];
}

-(void) zoomOutMapView:(id)sender
{
CGFloat currentZoom;
currentZoom = currentZoom - 1;

[self ZoominOutMap:currentZoom];
}

- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
NSLog(@"You tapped at %f,%f", coordinate.latitude, coordinate.longitude);
GMSMarker *marker = [[GMSMarker alloc] init];
//adds animation for adding marker
marker.appearAnimation = kGMSMarkerAnimationPop;
//draw marker on tapped position
marker.position = CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude);
marker.map = _mapView;
//set color of marker and make them draggable
marker.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]];
[marker setDraggable: YES];

// Create a rectangular path
GMSMutablePath *rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)];

// Create the polygon, and assign it to the map.
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = _mapView;
}

在代码中,您没有提供矩形路径。添加适当的多边形坐标以绘制GMSPolygon

// Create a rectangular path
GMSMutablePath *rect = [GMSMutablePath path];
[rect addCoordinate:CLLocationCoordinate2DMake(37.36, -122.0)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.45, -122.0)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.45, -122.2)];
[rect addCoordinate:CLLocationCoordinate2DMake(37.36, -122.2)];

// Create the polygon, and assign it to the map.
GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect];
polygon.fillColor = [UIColor colorWithRed:0.25 green:0 blue:0 alpha:0.05];
polygon.strokeColor = [UIColor blackColor];
polygon.strokeWidth = 2;
polygon.map = mapView;
更新:
回答

您必须从代码的“didTapAtCoordinate”中剪切此行,并将其粘贴到
viewDidLoad

#GMSMutablePath *rect = [GMSMutablePath path];#

那就行了

不,我行。Look://创建一个矩形路径GMSMutablePath*rect=[GMSMutablePath];[rect ADDCORATION:CLLocationCoordinate2DMake(坐标、纬度、坐标、经度)]@konyv12是它的单一坐标。对于多边形,您需要提供4个或更多坐标。我如何动态添加该坐标?@konyv12您到底想做什么?在用户点击地图时绘制多边形。