CLLocation 배열에 대해 mapview에서 경로를 만들려면 어떻게해야합니까? 폴리 라인을 만들고 걷는 방법으로 경로를 만들고 싶습니다. 내 나쁜 영어에 대한CLLocation (Swift) 배열에 대한 mapView의 경로 그리기
@IBAction func addPolyline(sender: AnyObject) {
let locations = [CLLocation(latitude: annotazioni.objectAtIndex(0).coordinate.latitude, longitude:annotazioni.objectAtIndex(0).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(1).coordinate.latitude, longitude:annotazioni.objectAtIndex(1).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(2).coordinate.latitude, longitude:annotazioni.objectAtIndex(2).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(3).coordinate.latitude, longitude:annotazioni.objectAtIndex(3).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(4).coordinate.latitude, longitude:annotazioni.objectAtIndex(4).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(5).coordinate.latitude, longitude:annotazioni.objectAtIndex(5).coordinate.longitude),
CLLocation(latitude: annotazioni.objectAtIndex(6).coordinate.latitude, longitude:annotazioni.objectAtIndex(6).coordinate.longitude)]
addPolyLineToMap(locations)
}
func addPolyLineToMap(locations: [CLLocation!]){
var coordinates = locations.map({ (location: CLLocation!) -> CLLocationCoordinate2D in
return location.coordinate
})
let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count: locations.count)
mapView.addOverlay(geodesic)
}
func mapView(mapView: MKMapView!, viewForOverlay overlay: MKOverlay!) -> MKOverlayRenderer! {
if (overlay is MKPolyline) {
let pr = MKPolylineRenderer(overlay: overlay);
pr.strokeColor = UIColor.blueColor().colorWithAlphaComponent(0.5);
pr.lineWidth = 5;
return pr;
}
return nil
}
죄송합니다 : 이 내 코드입니다 당신은 MKDirectRequest
및 MKDirections
를 사용하여 위치의 각 연속 쌍 사이 방향을 요청할 수 있습니다
영어는 정상입니다. SO는 사람들이 모든 종류의 언어를 구사하는 데 도움을주는 전세계적인 웹 사이트입니다. 질문으로 돌아 가면 ... 점 A에서 점 B에서 점 C 사이의 보행 선을 그리고 마지막으로 점 D에 도착하기를 원하십니까? –
예 :) thanks :) –