'polyline' is unvailable: APIs deprecated as iOS 7 and earlier are unavailable in Swift

424 views Asked by At

Trying to get the route from A to B and plot over the mapView, but complier says 'polyline' is unavailable: APIs deprecated as of iOS7 and earlier are unavailable in Swift

saw a similar thread here: How to use MKPolylineView in Swift, but in this case it is 'polyline' that does not work, not other attributes.

Any thoughts on workaround?

Thanks!

var req: MKDirectionsRequest = MKDirectionsRequest()
req.setSource(MKMapItem(placemark: MKPlacemark(coordinate: start, addressDictionary: nil)))
req.setDestination(MKMapItem(placemark: MKPlacemark(coordinate: dest, addressDictionary: nil)))
var dir: MKDirections = MKDirections(request: req)
dir.calculateDirectionsWithCompletionHandler ({
    (response: MKDirectionsResponse?, error: NSError?) in

if let routes = response?.routes{
     for route in routes{
         println(route.polyline)
         self.mapView.addOverlay(route.polyline)  // <- this line gives the error
     }
}
})
1

There are 1 answers

0
yi cheng On

Thanks Martin R, casting to MKRoute does the trick