Fus*_*dor 28 iphone mkmapview ios
我有一个要在地图上绘制的点数组,它已经被解码了:
- (void) drawRoute:(NSArray *) path {
NSInteger numberOfSteps = path.count;
CLLocationCoordinate2D coordinates[numberOfSteps];
for (NSInteger index = 0; index < numberOfSteps; index++) {
CLLocation *location = [path objectAtIndex:index];
CLLocationCoordinate2D coordinate = location.coordinate;
coordinates[index] = coordinate;
}
MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps];
[map addOverlay:polyLine];
}
Run Code Online (Sandbox Code Playgroud)
其中"map"是MKMapView的一个实例,并且路径表示已经解码的点集.
我认为用这条线[map addOverlay:polyLine];就可以了.我在某些页面中看到过这种方法:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 1.0;
return polylineView;
}
Run Code Online (Sandbox Code Playgroud)
polylineView在地图上实际绘制的是什么?我也尝试将MKPolyline(从上面的方法)传递给最后一个方法的"<MKOverlay> overlay"参数,但抛出异常.
我想我很亲密,但我现在不知道该怎么做.
请帮忙!非常感谢你提前.