【问题标题】:Polyline with gradient across width in iOS Google Maps SDKiOS Google Maps SDK中具有宽度渐变的折线
【发布时间】:2015-04-08 03:16:20
【问题描述】:
我有集成了 Google Maps SDK 的 iOS 应用。
我的路线具有默认样式,我可以通过spans 将length 中的颜色更改为渐变。
是否可以在width 中更新折线颜色并定义渐变(就像原来的谷歌地图应用一样)?:
更新:
我通过使用两条不同样式的相同折线添加了有限版本,但我肯定在寻找更好的解决方案:
我关注了official documentation,但没有找到任何引用。
【问题讨论】:
标签:
ios
google-maps
gradient
google-maps-sdk-ios
google-polyline
【解决方案1】:
我这样做:
GMSPath *path = [GMSPath pathFromEncodedPath:overview_route];
GMSPolyline *polyline = [GMSPolyline polylineWithPath:path];
polyline.strokeWidth = 5;
GMSStrokeStyle *greenToRed = [GMSStrokeStyle gradientFromColor:[UIColor greenColor] toColor:[UIColor redColor]];
polyline.spans = @[[GMSStyleSpan spanWithStyle:greenToRed]];
polyline.map = self.mapView;
【解决方案2】:
您可以参考文档了解更多信息:https://developers.google.com/maps/documentation/ios-sdk/shapes
例如,我使用从蓝色到深色(黑色)的两个渐变:
let brandBlue = GMSStrokeStyle.solidColor(.blue)
let nightBlue = GMSStrokeStyle.solidColor(.dark)
let gradientBlue = GMSStrokeStyle.gradient(from: .blue, to: .dark)
polyline.spans = [GMSStyleSpan(style: brandBlue),
GMSStyleSpan(style: nightBlue),
GMSStyleSpan(style: gradientBlue)]
polyline.map = mainMap.mapView