i already have a polyline in Swift4, how can i make the style of it to Dashed/Dotted line ??
let path = GMSMutablePath(path: GMSPath())
for marker in markerList {
bounds = bounds.includingCoordinate(marker.position)
path.add(marker.position)
}
let polyline = GMSPolyline(path: path)
polyline.strokeColor = UIColor(named: "Primary")!
polyline.strokeWidth = 3.0
polyline.geodesic = true
polyline.map = mapView
Like this map
You need to implement func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer
delegate method and using renderer.lineDashPhase
and renderer.lineDashPattern
properties you should be able to achive what you need
code example
func mapView(_ mapView: MKMapView, rendererFor overlay: MKOverlay) -> MKOverlayRenderer {
let renderer = MKPolylineRenderer(overlay: overlay)
renderer.strokeColor = UIColor.red
renderer.lineWidth = 4.0
renderer.lineDashPhase = 2
renderer.lineDashPattern = [NSNumber(value: 1),NSNumber(value:5)]
return renderer
}
result
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With