I created a table view with a cell that has a mapView. I add annotation and try to make a route between them. I did the same with the same code from another view controller, which works fine, but couldn't do the same in the user tableview cell that has a map. It does not go inside viewForAnnotationor rendererForOverlay. I have included mapDelegate in the view controller. So please, where is my problem?
let cell = tableView.dequeueReusableCellWithIdentifier("cell8") as! MapViewTableViewCell
cell.mapView.delegate = self
cell.mapView.setRegion(cell.mapView.regionThatFits(MKCoordinateRegionMakeWithDistance(sourceLocation.placemark.coordinate, 1800, 1800)), animated: true)
cell.calculateRoute(cell.endLocations, secondArray: cell.waypointLocations)
for item in cell.endLocations {
let annotation = MKPointAnnotation()
annotation.coordinate = item.placemark.coordinate
if cell.endLocations.indexOf(item) == 0 {
annotation.title = "start"
}
else {
annotation.title = "end"
}
cell.mapView.addAnnotation(annotation)
}
return cell
And I did and an extension for the card
extension CarViewController : MKMapViewDelegate{
func mapView(mapView: MKMapView, viewForAnnotation annotation: MKAnnotation) -> MKAnnotationView? {
if (annotation.title! == "start") {
let pinAnnotation = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
pinAnnotation.pinColor = .Green
return pinAnnotation
}
else if (annotation.title! == "end") {
let pinAnnotation = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "identifier")
pinAnnotation.pinColor = .Purple
return pinAnnotation
}
return nil
}
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolyline {
let polylineRenderer = MKPolylineRenderer(overlay: overlay)
polylineRenderer.strokeColor = UIColor.greenColor()
polylineRenderer.alpha = 0.80
polylineRenderer.lineWidth = 5
return polylineRenderer
}
return MKPolylineRenderer()
}
}
source
share