I have a problem drawing a Polyline on my MapKit map, I am supposed to be trying to draw a line where the user is going, the problem is that when I move the user's position it only draws a point in the new position but does not trace the complete line
I have already tried to paint the line with a starting point and a starting point, but it does not work for me, it is assumed that if the user walks his position is updated and he should go drawing the line
This is my method didUpdateLocations:
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
if let location = locations.last{
self.currentLocation = location
mapKit.centerCoordinate = location.coordinate
//Validamos si el usuario quiere recordar su ruta
if SettingsViewController.recordRutaOn{
points.append(location)
print("Estamos registrando la ruta del usuario")
}
//Prueba para pintar la ruta
print((locations.last?.coordinate.latitude)!,(locations.last?.coordinate.longitude)!)
var rutaPoly = CLLocationCoordinate2D(latitude: (locations.last?.coordinate.latitude)!, longitude: (locations.last?.coordinate.longitude)!)
let polyline = MKPolyline(coordinates: &rutaPoly, count: locations.count)
mapKit.add(polyline)
if self.currentLocation == nil{
self.currentAnnotation = MKPointAnnotation()
self.currentAnnotation?.coordinate = location.coordinate
self.mapKit.addAnnotation(self.currentAnnotation!)
}
}
}
And this is my renderFor method:
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
if overlay is MKPolyline{
let polyline = overlay
let polyLineRender = MKPolylineRenderer(overlay: polyline)
polyLineRender.strokeColor = UIColor.blue
polyLineRender.lineWidth = 2.0
return polyLineRender
}
return MKPolylineRenderer()
}
I don't understand what I'm doing wrong that only one point is drawn