I have iOS app with the Google Maps SDK integrated. My route has default style and I'm able to change the color to be gradient in length
via spans
.
我有iOS应用程序,集成了Google Maps SDK。我的路线有默认样式,我可以通过跨度将颜色更改为渐变长度。
Is it possible to update polyline color and define gradient in width
instead (like original Google Maps app has)?:
是否可以更新折线颜色并在宽度上定义渐变(就像原始Google地图应用程序一样)?:
UPDATE: I have added limited version by using two identical polylines with different styles but I'm definitely looking for a better solution:
更新:我通过使用两个具有不同样式的相同折线添加了限量版本,但我肯定在寻找更好的解决方案:
I followed the official documentation and didn't find any references of that.
我按照官方文档,没有找到任何参考。
2 个解决方案
#1
7
I do this:
我这样做:
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
0
You can refer to the documentation for more info: https://developers.google.com/maps/documentation/ios-sdk/shapes
您可以参阅文档了解更多信息:https://developers.google.com/maps/documentation/ios-sdk/shapes
I use for example two gradients from blue to dark(black):
我使用例如从蓝色到黑色(黑色)的两个渐变:
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
#1
7
I do this:
我这样做:
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
0
You can refer to the documentation for more info: https://developers.google.com/maps/documentation/ios-sdk/shapes
您可以参阅文档了解更多信息:https://developers.google.com/maps/documentation/ios-sdk/shapes
I use for example two gradients from blue to dark(black):
我使用例如从蓝色到黑色(黑色)的两个渐变:
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