Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polyline with gradient across width in iOS Google Maps SDK

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.

Is it possible to update polyline color and define gradient in width instead (like original Google Maps app has)?:

enter image description here

UPDATE: I have added limited version by using two identical polylines with different styles but I'm definitely looking for a better solution: enter image description here

I followed the official documentation and didn't find any references of that.

like image 919
Alexey Strakh Avatar asked Oct 18 '25 16:10

Alexey Strakh


1 Answers

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;
like image 73
Profezy Avatar answered Oct 20 '25 08:10

Profezy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!