How can I change the color of an MGLPolyline? I had looked here but the answer did not work. I also tried some other code but it was too dependant on apple maps. So how can I ch
You can set the color and width of a polyline in MKMapViewDelegate function only. Check example below.
public func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let polyLine = overlay as? MKPolyline
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.lineWidth = 2.5
renderer.strokeColor = UIColor(red: 47/255, green: 62/255, blue: 158/255, alpha: 1.0)
return renderer
}
You have to make mapView.delegate = self
Then implement this method:
func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {
return .blue
}