GMSPolyline 与多个引脚之间的点图案

问题描述 投票:0回答:0

我正在尝试在 GMSMapView 上绘制虚线折线。到目前为止,我所取得的成就是在地图上添加了一条虚线折线。为此我写了下面的代码:

polyLine.strokeWidth = 10
polyLine.strokeColor = UIColor(red: 95/255, green: 89/255, blue: 89/255, alpha: 1.0)
let styles: [GMSStrokeStyle] = [GMSStrokeStyle.solidColor(UIColor.clear), GMSStrokeStyle.solidColor(UIColor.red)]
let scale = 1.0 / testMap.projection.points(forMeters: 1, at: testMap.camera.target)
let solidLine = NSNumber(value: 10.0 * Float(scale))
let gap = NSNumber(value: 10.0 * Float(scale))        
let span = GMSStyleSpans(polyLine.path!, styles, [solidLine, gap], GMSLengthKind.rhumb)        
polyLine.spans = span

使用此代码,我得到一条以 10x10 正方形作为破折号的折线。

对于虚线折线,我尝试将点图像设置为 GMSStrokeStyle 中的纯色之一,如下所示:

let styles: [GMSStrokeStyle] = [GMSStrokeStyle.solidColor(UIColor(patternImage: UIImage(named: "dot1.jpg")!)), GMSStrokeStyle.solidColor(UIColor.red)]

我尝试过的另一个解决方案是here

使用此解决方案,地图需要大量时间来加载和刷新。因此,应用程序在加载地图时挂起。

在 iOS 中的 Google 地图上绘制点折线还有哪些其他方法?

ios swift google-maps google-polyline gmsmapview
© www.soinside.com 2019 - 2024. All rights reserved.