Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created March 27, 2019 18:08
Show Gist options
  • Save SergLam/b84af1d7c7c070f81e38219459cdf808 to your computer and use it in GitHub Desktop.
Save SergLam/b84af1d7c7c070f81e38219459cdf808 to your computer and use it in GitHub Desktop.
Google Maps iOS Polyline with dashes
func drawPolyline() {
let path = GMSMutablePath()
path.add(CLLocationCoordinate2D(latitude: 50.014787, longitude: 36.232725))
path.add(CLLocationCoordinate2D(latitude: 50.014997, longitude: 36.233533))
path.add(CLLocationCoordinate2D(latitude: 50.016942, longitude: 36.232385))
path.add(CLLocationCoordinate2D(latitude: 50.016019, longitude: 36.226335))
path.add(CLLocationCoordinate2D(latitude: 50.010419, longitude: 36.227913))
let rectangle = GMSPolyline(path: path)
rectangle.map = contentView.mapView
let styles = [
GMSStrokeStyle.solidColor(UIColor.red),
GMSStrokeStyle.solidColor(UIColor.clear)
]
let points = contentView.mapView.projection.points(forMeters: 1, at: contentView.mapView.camera.target)
let scale = 1.0 / points
let lengths: [NSNumber] = [NSNumber(value: Float(1 * scale)), NSNumber(value: Float(1 * scale))]
rectangle.spans = GMSStyleSpans(path, styles, lengths, GMSLengthKind.rhumb)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment