I have an array of points to be drawn on a map, its already decoded:
- (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];
}
where "map" is an instance of MKMapView, and path the array representing the already decoded set of points.
I thought that with the line [map addOverlay:polyLine];
it would be drawn. I've seen in some pages this method:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id <MKOverlay>)overlay {
MKPolylineView *polylineView = [[MKPolylineView alloc] initWithPolyline:overlay];
polylineView.strokeColor = [UIColor redColor];
polylineView.lineWidth = 1.0;
return polylineView;
}
Is the polylineView what is actually drawn on map? I've tried also to pass the MKPolyline (from the method above) to the "<MKOverlay> overlay" argument of this last method, but throws an exception.
I think I'm close, but I don't know what to do now.
Please help! Thank you very much in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…