gpt4 book ai didi

swift - 如何绘制行走路线(点)

转载 作者:行者123 更新时间:2023-11-30 10:35:17 25 4
gpt4 key购买 nike

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
}

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

最佳答案

试试这个:

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

关于swift - 如何绘制行走路线(点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58181805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com