0

我尝试使用以下代码添加从用户位置到目的地的折线,我确信我已经符合委托并确保用户在授权状态下处于 authorizedAlway 模式。但是,控制台生成了此错误消息,显示“ [UserSession] maps short session requested but session sharing is not enabled ”我找不到任何与如何解决此错误相关的信息。

    func generatePolyLine(toDestination destination: MKMapItem) {
    
    let request = MKDirections.Request()
    //start from the user's current location to find the ride
    request.source = MKMapItem.forCurrentLocation()
    request.destination = destination
    request.transportType = .automobile

    let directionRequest = MKDirections(request: request)

    directionRequest.calculate { response, error in
        if let error = error {
            print("Error calculating direction request \(error)")
        }
        guard let response = response else { return }
        self.route = response.routes.first
        guard let polyLine = self.route?.polyline else { return }
        self.mapView.addOverlay(polyLine, level: .aboveRoads)
        
    }
}
4

1 回答 1

0

您是否添加了委托方法来指定渲染器?就像是:

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    if let polyline = overlay as? MKPolyline {
        let renderer = MKPolylineRenderer(polyline: polyline)
        renderer.lineWidth = 3.0
        renderer.alpha = 0.5
        renderer.strokeColor = UIColor.blue
        
        return renderer
    }
    if let circle = overlay as? MKCircle {
        let renderer = MKCircleRenderer(circle: circle)
        renderer.lineWidth = 3.0
        renderer.alpha = 0.5
        renderer.strokeColor = UIColor.blue
        
        return renderer
    }
    return MKCircleRenderer()
}
于 2022-02-07T08:57:38.013 回答