ios - 如何插入数组值以根据长/纬度值绘制多边形-Google Maps iOS?

标签 ios objective-c xcode google-maps

我正在尝试GMSPolygon * polygon = [GMSPolygon geometricWithPath: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;

关于ios - 如何插入数组值以根据长/纬度值绘制多边形-Google Maps iOS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42809299/

相关文章:

iphone - 添加本地化时,Appstore 提示名称已存在?

objective-c - 在 NSCache 中使用 NSPurgeabledata 有什么意义?

ios - 图片加载到 UIButton 时不会显示

ios - 10.00 秒后场景更新失败或 0x000000008badf00d 异常

ios - 将 FaceTime 功能集成到 iPad 应用程序中

iphone - ID : Library not found for -lMBProgressHUD

swift - 文本字段 - 标签 - 按钮 根据输入回答

iphone - 无法在 plist 文件中写入 bool 值

iphone - 调整 ASIWebPageRequest 的 header 搜索路径

iOS、MPNowPlayingInfoCenter 暂停/播放按钮不起作用?