我正在尝试将多边形叠加添加到MKMapKit贴图上。地图出现了 - 但是多边形没有...我错过了一些明显的东西吗?
附加代码:
- (void)viewDidLoad
{
[super viewDidLoad];
self.mapView.showsPointsOfInterest = NO;
CLLocationCoordinate2D worldCoords[4] = { {43,-100}, {43,-80}, {25,-80}, {25,-100} };
MKPolygon *worldOverlay = [MKPolygon polygonWithCoordinates:worldCoords count:4];
[self.mapView addOverlay:worldOverlay level:MKOverlayLevelAboveRoads];
}
Renderer班......
- (MKOverlayRenderer *)mapView:(MKMapView *)mapView rendererForOverlay:(id<MKOverlay>)overlay
{
if (![overlay isKindOfClass:[MKPolygon class]]) {
return nil;
}
MKPolygon *polygon = (MKPolygon *)overlay;
MKPolygonRenderer *renderer = [[MKPolygonRenderer alloc] initWithPolygon:polygon];
renderer.fillColor = [[UIColor darkGrayColor] colorWithAlphaComponent:0.4];
return renderer;
}
任何帮助将不胜感激!
由于 盖
答案 0 :(得分:-3)
我偶然发现了答案!
在上述评论中,Anna的帮助帮助我完成了图层工作 - 似乎必须在添加图层后启动mapView 。所以
之后[self.mapView addOverlay:worldOverlay level:MKOverlayLevelAboveRoads];
你需要
mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];