let legs = itineraries[0]["legs"].arrayValue
for route in legs
{
let mode = route["mode"].string ?? "-"
let routeOverviewPolyline = route["legGeometry"].dictionary
let points = routeOverviewPolyline?["points"]?.stringValue
let path = GMSPath.init(fromEncodedPath: points!)
let polyline = GMSPolyline(path: path)
polyline.strokeColor = color
polyline.strokeWidth = 4
polyline.map = self.indexView.mapView
}
此代码用于绘制线条。 像在谷歌地图应用程序中一样,我想绘制步行路线。虚线和圆形。 我找不到例子。
答案 0 :(得分:0)
尝试一下:
extension GMSMapView {
func drawPolyline(_ pathString: String) -> GMSPolyline? {
guard let path = GMSPath(fromEncodedPath: pathString) else { return nil }
let polyline = GMSPolyline(path: path)
polyline.strokeWidth = 3.0
polyline.geodesic = true
let styles: [GMSStrokeStyle] = [.solidColor(.black), .solidColor(.clear)]
let scale = 1.0 / projection.points(forMeters: 1.0, at: camera.target)
let dashLength = NSNumber(value: 3.5 * Float(scale))
let gapLength = NSNumber(value: 3.0 * Float(scale))
polyline.spans = GMSStyleSpans(path, styles, [dashLength, gapLength], .rhumb)
polyline.map = self
return polyline
}
}