如何绘制路线行走(点)

时间:2019-10-01 09:25:30

标签: swift google-maps-sdk-ios google-polyline gmsmapview

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
}

此代码用于绘制线条。 像在谷歌地图应用程序中一样,我想绘制步行路线。虚线和圆形。 我找不到例子。

1 个答案:

答案 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
   }
}