Swift 3 - MKMapView中的Line越来越厚

时间:2018-01-03 13:31:03

标签: ios swift mkmapview

我正在使用MKMapViewPolyLine概念绘制一条线。但是当绘制线条时,线条会越来越粗。我希望整条路线都有一条线。

我的代码: -

 func assigArray() {
    if self.lat.count == self.lon.count {
        for i in 0 ..< self.lat.count {
            let destination = CLLocationCoordinate2DMake(self.lat[i], self.lon[i])
            coordinateArray.append(destination)
        }
        self.mapp()
    }

}
func mapp() {
    let coords2 = CLLocationCoordinate2D(latitude: lat.last!, longitude: lon.last!)
    let testline = MKPolyline(coordinates: coordinateArray, count: coordinateArray.count)
    //Add `MKPolyLine` as an overlay.
    map.add(testline)

    map.delegate = self

    map.centerCoordinate = coords2
    map.region = MKCoordinateRegion(center: coords2, span: MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02))
}
  func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let renderer = MKPolylineRenderer(overlay: overlay)
    renderer.strokeColor = UIColor.red
    renderer.lineWidth = 2.0
    return renderer
}

line is getting thicker

0 个答案:

没有答案