0

我正在两点之间绘制一条折线,供用户使用位置管理器跟踪并执行 didUpdateLocations 中的代码。如果用户转弯不正确,有没有办法触发这条折线的重绘?这意味着如果用户位置超出路线 - 我可以触发重新计算吗?

本质上这是折线背后的逻辑:

directionRequest.transportType = .automobile
        let directions = MKDirections(request: directionRequest)
        directions.calculate { (response, error) in
            guard let response = response else { return }
            let route = response.routes.first
            if let line = route?.polyline {
                self.mapView.addOverlay(line, level: .aboveRoads)
                DispatchQueue.main.asyncAfter(deadline: .now()) { [self] in
                    let distanceAway = String(format:"%.0f", route!.distance / 1609)
                    let minutesAway = route!.expectedTravelTime / 60
                    if let first = mapView.overlays.first {
                    //Other Actions
                        
                    }
                }
            }
        }
4

0 回答 0