Created
March 27, 2019 18:08
-
-
Save SergLam/b84af1d7c7c070f81e38219459cdf808 to your computer and use it in GitHub Desktop.
Google Maps iOS Polyline with dashes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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