2012-06-06 4 views
25

나는 점의 배열이지도에 그려 질 필요는 그 이미 복호화 :MapView에서 MKPolyline을 그리는 방법은 무엇입니까?

- (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]; 
} 

는 여기서 "매핑"은 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; 
} 

실제로 폴리 라인 뷰가지도에 그려지는 부분이 있습니까? 위의 메서드에서 MKPolyline을이 마지막 메서드의 "< MKOverlay> 오버레이"인수로 전달하려고 시도했지만 예외가 throw됩니다.

나는 가깝다고 생각하지만 지금 어떻게해야할지 모르겠다.

도와주세요! 대단히 감사드립니다.

+2

이 코드는 iOS7에서 더 이상 사용되지 않습니다. –

답변

13

완료합니다.

매우 어리 석었지만 MapView의 대리인을 설정하지 않았습니다. 단순히 [map setDelegate : self]를 추가하십시오. 트릭을 했어.

고맙습니다.

4

좌표가 & 인 MKPolyline을 맵보기에 추가하면됩니다.

MKPolyline *polyLine = [MKPolyline polylineWithCoordinates:coordinates count:numberOfSteps]; 
    [map addOverlay:polyLine]; 

당신은 어떤 좌표를 통해 폴리 라인을 그리는 방법에 대한 튜토리얼 here을 찾을 수 있습니다. 편집 : URL이 더 이상 유효하지 않습니다. 이 URL의 아카이브 된 버전 here을 찾을 수 있습니다.

+0

보관 된 버전의 링크 : http://web.archive.org/web/20120906022305/http://navarra.ca/?p=786 – Brian

관련 문제