我已使用以下代码在Google地图中添加多边形
for(int i = 0; i < [[polygon valueForKey:@"coordinates"] count]; i++){
[self.path addCoordinate:CLLocationCoordinate2DMake([[[[polygon valueForKey:@"coordinates"] objectAtIndex:i] objectAtIndex:1] floatValue],[[[[polygon valueForKey:@"coordinates"] objectAtIndex:i] objectAtIndex:0] floatValue])];
}
GMSPolygon *rectangle = [GMSPolygon polygonWithPath:self.path];
rectangle.fillColor = [UIColor colorWithRed:255.0/255.0 green:0.0/255.0 blue:0.0/255.0 alpha:0.4];
rectangle.map = self.mapView;
rectangle.strokeColor=[UIColor redColor];
[self.restrictedLocations addObject:rectangle];
CLLocation *userLocation = [[mymanager sharedManager] userLocation];
[self.mapView bringSubviewToFront:self.locationMarkerView];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:userLocation.coordinate.latitude
longitude:userLocation.coordinate.longitude
zoom:7];
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
我可以在地图中看到多边形,并添加了以下代码以从地图中删除多边形。
[self.mapView clear];
并且这不起作用,我仍然可以在谷歌地图中看到多边形。
请帮帮我
UPDATE
My GSMMapView is not programmatically created , actually added one UIView and changed its class to GSMMApView. is that the issue ?
当我添加日志并运行此添加多边形方法时, 所以我得到了以下值
我第一次在地图上看到多边形,那时我的日志
NSLog(@"%@",[mapView description]);
显示如下
<GMSMapView: 0x1610eb760; frame = (0 0; 320 504); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x16127e4f0>; layer = <GMSMapLayer: 0x1610ebc10>>
然后我试图运行[mapView clear]
并且它不起作用所以我也得到了日志
第二次我的日志
NSLog(@"%@",[mapView description]);
显示如下
<GMSMapView: 0x15ff9c550; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x162340e30>; layer = <GMSMapLayer: 0x15ffca4b0>>