1

I tried to add a polyline from the user's location to destination by using the following code, I am sure that I have conformed to the delegate and ensure that the user is in authorizedAlway mode in the authorization status. However, the console generated this error message saying "[UserSession] maps short session requested but session sharing is not enabled" I can not find anything related on how to solve this error.

    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)
        
    }
}
Ray
  • 13
  • 1
  • 2

1 Answers1

0

Did you add the delegate method to specify the renderer? Something like:

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()
}
Magnas
  • 3,832
  • 5
  • 33
  • 48
  • yes i did. It does not work either. `private func mapView (_ mapView: MKMapView, viewFor overlay: MKOverlay) -> MKOverlayRenderer { if let route = self.route { let polyLine = route.polyline let lineRenderer = MKPolygonRenderer(overlay: polyLine) lineRenderer.strokeColor = .mainBlueColor lineRenderer.lineWidth = 4 return lineRenderer } return MKOverlayRenderer() }` – Ray Feb 07 '22 at 13:53