如何插入数组值以根据long / lat值绘制多边形 – Google Maps iOS?

我正在尝试GMSPolygon * polygon = [GMSPolygon polygonWithPath:rect]; 用户绘制抽头坐标的多边形的方法。 以下是我存储点击坐标的方法:

// array made of clicked coordinates NSMutableArray *latitudeTappedCoordinates = [NSMutableArray array]; NSMutableArray *longitudeTappedCoordinates = [NSMutableArray array]; NSUInteger numberOfLongitudeCoordinates = [longitudeTappedCoordinates count]; NSUInteger numberOfLatitudeCoordinates = [latitudeTappedCoordinates count]; for (int i = 2; i < numberOfLatitudeCoordinates; i++) { [latitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.latitude]]; } for (int i = 2; i < numberOfLongitudeCoordinates; i++) { [longitudeTappedCoordinates addObject:[NSNumber numberWithInt:coordinate.longitude]]; } 

在此之后,我有以下内容:

 // polygon GMSMutablePath *rect = [GMSMutablePath path]; [rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; GMSPolygon *polygon = [GMSPolygon polygonWithPath:rect]; 

如你所见,这条线

 [rect addCoordinate:CLLocationCoordinate2DMake(coordinate.latitude,coordinate.longitude)]; 

只接受一个属性。 我希望它接受上面数组init中的所有值,因此它可以绘制多边形。 我怎样才能做到这一点?

第一个存储浮点值不是数组中的int值。 然后

添加界面

  NSMutableArray *latitudeTappedCoordinates; NSMutableArray *longitudeTappedCoordinates; 

你可以这样做:

 // Create a rectangular path GMSMutablePath *rect = [GMSMutablePath path]; CLLocationCoordinate2D event; for (int i = 0; i <= [longitudeTappedCoordinates count]-1; i++) { event.latitude = [[latitudeTappedCoordinates objectAtIndex:i] floatValue]; event.longitude = [[longitudeTappedCoordinates objectAtIndex:i] floatValue]; [rect addCoordinate:event]; } 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;