如何绘制路线(点)

问题描述 投票:0回答:1
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
}

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

swift google-maps-sdk-ios google-polyline gmsmapview
1个回答
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
   }
}
© www.soinside.com 2019 - 2024. All rights reserved.