Для извещателей о границах патента, проверьте контроллер, который содержит представление в Интерфейсном Разработчике XCode в функциональности "иерархии представления отладки"

тоящее время я отслеживаю свое местоположение в MKMapView. Моя цель - нарисовать более изящный путь, идентичный MKPolyline, созданному из отслеживаемых мест.

Я попытался: сохранить все координаты местоположения в массиве CLLocation. Выполните итерацию по этому массиву и сохраните координаты широты / долготы в массиве CLLocationCoordinate2D. Затем убедитесь, что ломаная линия находится на экране, чтобы затем преобразовать все координаты местоположения в CGPoints.

Текущая попытка:

@IBOutlet weak var bezierPathView: UIView! 

var locations = [CLLocation]() // values from didUpdateLocation(_:)

func createBezierPath() {
    bezierPathView.isHidden = false

        var coordinates = [CLLocationCoordinate2D]()
        for location in locations {
            coordinates.append(location.coordinate)
        }

        let polyline = MKPolyline(coordinates: coordinates, count: coordinates.count)
        fitPolylineInView(polyline: polyline)

        let mapPoints = polyline.points()

        var points = [CGPoint]()

        for point in 0...polyline.pointCount
        {
            let coordinate = MKCoordinateForMapPoint(mapPoints[point])
            points.append(mapView.convert(coordinate, toPointTo: polylineView))
        }

        print(points)

        let path = UIBezierPath(points: points)
        path.lineWidth = 2.0
        path.lineJoinStyle = .round

        let layer = CAShapeLayer(path: path, lineColor: UIColor.red, fillColor: UIColor.black)
        bezierPathView.layer.addSublayer(layer)
}

extension UIBezierPath {
    convenience init(points:[CGPoint])
    {
        self.init()

        //connect every points by line.
        //the first point is start point
        for (index,aPoint) in points.enumerated()
        {
            if index == 0 {
                self.move(to: aPoint)
            }
            else {
                self.addLine(to: aPoint)
            }
        }
    }
}

extension CAShapeLayer
{
    convenience init(path:UIBezierPath, lineColor:UIColor, fillColor:UIColor)
    {
        self.init()
        self.path = path.cgPath
        self.strokeColor = lineColor.cgColor
        self.fillColor = fillColor.cgColor
        self.lineWidth = path.lineWidth

        self.opacity = 1
        self.frame = path.bounds
    }
}

Я могу вывести на консоль точки, сохраненные из метода convert (_ :) (не уверен, что они правильные). Тем не менее, на bezierPathView не выводится, что приводит к пустому белому контроллеру фонового представления.

Ответы на вопрос(1)

Ваш ответ на вопрос