如何使蓝线跟随折线(橙色线)?

时间:2018-09-19 18:31:50

标签: swift mapkit polyline direction

我试图弄清楚如何获得方向代码(蓝线)以跟随橙色的折线代码。折线代码只是固定的x,y位置代码。如您所见,我已经附加了图像,并且正在使用Swift4。图钉只是橙色线着陆的区域,想让方向降落在那里(蓝色线),然后停止而又不跟随整个橙色线

方向代码(蓝线):

let request = MKDirectionsRequest()
        request.source = MKMapItem.forCurrentLocation()

    request.destination = destination
    request.requestsAlternateRoutes = false


    let directions = MKDirections(request: request)

    directions.calculate {
        (response, error) -> Void in

        guard let response = response else {
            if let error = error {
                print("Error: \(error)")
            }

            return
        }
        let route = response.routes[0]
        self.mapView.add((route.polyline), level: MKOverlayLevel.aboveRoads)
        self.mapView.setCenter(route.polyline.coordinate, animated: true)

       // let rect = route.polyline.boundingMapRect
       // self.mapView.setRegion(MKCoordinateRegionForMapRect(rect), animated: true)
    }
}
}

我知道这段代码:self.mapView.add((route.polyline),level:MKOverlayLevel.aboveRoads)紧随其后。我试图找出一种不同的方法使它遵循橙色线(即折线)。如果有人可以帮助,那就太好了。

enter image description here

0 个答案:

没有答案