I’m having some trouble adding an MKPolyline to my mapView. I’m trying to add a simply overlay of a blue line that traces changes in the current location. Here is the code:
//CLLocationManagerDelegate methods
func locationManager(manager: CLLocationManager, didUpdateToLocation newLocation: CLLocation, fromLocation oldLocation: CLLocation) {
if let oldLocationNew = oldLocation as CLLocation? {
let oldCoordinates = oldLocationNew.coordinate
let newCoordinates = newLocation.coordinate
var area = [oldCoordinates, newCoordinates]
let polyline = MKPolyline(coordinates: &area, count: area.count)
map.addOverlay(polyline)
}
}
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
}
func locationManager(manager: CLLocationManager, didFailWithError error: NSError) {
print(error)
}
//MKMapViewDelegate methods
func mapView(mapView: MKMapView, rendererForOverlay overlay: MKOverlay) -> MKOverlayRenderer {
let pr = MKPolylineRenderer(overlay: overlay)
if overlay is MKPolyline {
pr.strokeColor = UIColor.blueColor()
pr.lineWidth = 5
}
return pr
}
}
Any help would be appreciated.
Thanks