Ios 地图上的多段线不可见

Ios 地图上的多段线不可见,ios,swift,dictionary,mkmapview,polyline,Ios,Swift,Dictionary,Mkmapview,Polyline,我尝试将多段线添加到地图,但它不可见 locationManager.startUpdatingLocation() guard let locValue: CLLocationCoordinate2D = locationManager.location?.coordinate else { return } Map.setCenter(locValue, animated: true) if !locations.contains(where: {$0.latitude == lo

我尝试将多段线添加到地图,但它不可见

locationManager.startUpdatingLocation()
guard let locValue: CLLocationCoordinate2D =
    locationManager.location?.coordinate else { return }
Map.setCenter(locValue, animated: true)

if !locations.contains(where: {$0.latitude == locValue.latitude && $0.longitude == locValue.longitude}) {
    locations.append(locValue)
    NSLog("Add: %f %f -> Count: %i", locValue.latitude, locValue.longitude, locations.count)

    let polyline = MKPolyline(coordinates: &locations, count: locations.count)
    Map.addOverlay(mapView(Map, rendererFor: polyline).overlay)
}
“我的”地图视图功能:

func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
    let polyLine = overlay
    let polyLineRenderer = MKPolylineRenderer(overlay: polyLine)
    polyLineRenderer.strokeColor = UIColor.red
    polyLineRenderer.lineWidth = 5.0
    return polyLineRenderer
}
你可以试试

self.map.delegate = self

let polyline = MKPolyline(coordinates:locations, count: locations.count) 
self.map.addOverlay(routeLine)