我正在尝试制作导航应用
但是当我尝试导航并显示“MKRoutePolyline”时,这个应用程序崩溃了
interiorPolygons:发送到实例0x14ed4b4d0的无法识别的选择器“
我的代码怎么了?
import UIKit import MapKit class MapViewController: UIViewController,MKMapViewDelegate { var farm:Farm! var currentPlacemark:CLPlacemark? let locationManager = CLLocationManager() var currentTransportType = MKDirectionsTransportType.Automobile var currentRoute:MKRoute? @IBOutlet var mapView:MKMapView! @IBAction func showDirection(sender: AnyObject){ let directionRequest = MKDirectionsRequest() directionRequest.source = MKMapItem.mapItemForCurrentLocation() let destinationPlacemark = MKPlacemark(placemark: currentPlacemark!) directionRequest.destination = MKMapItem(placemark: destinationPlacemark) directionRequest.transportType = currentTransportType let directions = MKDirections(request: directionRequest) directions.calculateDirectionsWithCompletionHandler { (routeResponse,routeError) -> Void in guard let routeResponse = routeResponse else { if let routeError = routeError { print("Error: \(routeError)") } return } let route = routeResponse.routes[0] self.currentRoute = route self.mapView.removeOverlays(self.mapView.overlays) self.mapView.addOverlay(route.polyline,level: MKOverlayLevel.AboveRoads) } } func mapView(mapView: MKMapView,rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer { let renderer = MKPolygonRenderer(overlay: overlay) renderer.strokeColor = UIColor.yellowColor() renderer.lineWidth = 3.0 return renderer }
解决方法
看来你想渲染一条线.
但多边形是一种形状
所以你的代码应该是:
但多边形是一种形状
所以你的代码应该是:
let renderer = MKPolylineRenderer(overlay: overlay)
但不是:
let renderer = MKPolygonRenderer(overlay: overlay)
在
func mapView(mapView: MKMapView,rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer