【发布时间】:2011-07-25 08:42:13
【问题描述】:
我正在尝试在 iOS 4.0 中的 MKMapView 上绘制 MKPolygon。我有一个 NSArray,其中包含自定义对象,其中包括纬度/经度属性。我在下面有一个代码示例:
- (void)viewDidLoad {
[super viewDidLoad];
dataController = [[DataController alloc] initWithMockData];
coordinateData = [dataController getCordData];
CLLocationCoordinate2D *coords = NULL;
NSUInteger coordsLen = 0;
/* How do we actually define an array of CLLocationCoordinate2d? */
MKPolygon *polygon = [MKPolygon polygonWithCoordinates:coords count:coordsLen];
[mapView addOverlay: polygon];
}
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay
{
MKPolygonView *polygonView = [[MKPolygonView alloc] initWithPolygon: routePolygon];
NSLog(@"Attempting to add Overlay View");
return polygonView;
}
我的理解是这样的:
- 我需要创建 MKPolygon
- 将叠加层添加到 MapView
- 这将触发创建 MKPolygonView。
我的问题是如何获取包含在 NSArray (coordinateData) 中的自定义对象并将这些对象转换为 CLLocationCoordinate2d 数组,以便 Polygon 可以解释和渲染?我不确定 CLLocationCoordinate2d 甚至是一个数组吗?有人可以澄清一下吗?
【问题讨论】:
标签: ios objective-c iphone mkmapview mkpolygon