我在互联网上搜索但我无法找到答案。可以在MKPolygon中画一个洞吗?像这样:
我记得我看过这样的东西,但我不确定它是否与iOS有关。有可能这样做(如果是的话)我应该如何开始?
谢谢
答案 0 :(得分:6)
要正确执行此操作,您应该真正查看MKPolygon的interiorPolygons
部分。
答案 1 :(得分:1)
正如@incanus指出的那样,你可以定义一个interiorPolygons
数组。例如:
NSUInteger interiorCount = 5;
CLLocationCoordinate2D interiorCoordinates[interiorCount];
interiorCoordinates[0] = CLLocationCoordinate2DMake(...);
interiorCoordinates[1] = CLLocationCoordinate2DMake(...);
interiorCoordinates[2] = CLLocationCoordinate2DMake(...);
interiorCoordinates[3] = CLLocationCoordinate2DMake(...);
interiorCoordinates[4] = CLLocationCoordinate2DMake(...);
MKPolygon* interiorPolygon = [MKPolygon polygonWithCoordinates:interiorCoordinates
count:interiorCount];
interiorPolygon.title = @"interior polygon";
NSUInteger count = 5;
CLLocationCoordinate2D coordinates[count];
coordinates[0] = CLLocationCoordinate2DMake(...);
coordinates[1] = CLLocationCoordinate2DMake(...);
coordinates[2] = CLLocationCoordinate2DMake(...);
coordinates[3] = CLLocationCoordinate2DMake(...);
coordinates[4] = CLLocationCoordinate2DMake(...);
MKPolygon* polygon = [MKPolygon polygonWithCoordinates:coordinates
count:count
interiorPolygons:@[interiorPolygon]];
polygon.title = @"exterior polygon";
[self.mapView addOverlay:polygon];
产量:
归功于@incanus!