繁体   English   中英

iOS15折线不显示在mapView上

[英]iOS15 polyline does not show on mapView

我尝试使用以下代码添加从用户位置到目的地的折线,我确信我已经符合委托并确保用户在授权状态下处于授权状态。 但是,控制台生成了此错误消息,显示“ [UserSession] 映射请求的短会话但未启用会话共享<\/strong>”我找不到有关如何解决此错误的任何信息。

    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)
        
    }
}

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

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()
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM