问题
I'm using google map sdk in iOS 7.1
How can I set color for GMSPolyline, the default is black. I have try with setStrokeColor and setSpans:
setStrokeColor:UIColorFromRGB(0xff0000, 1)
setSpans:@[[GMSStyleSpan spanWithColor:UIColorFromRGB(0xff0000, 1)]]
but it no have effect, I can only change the opacity by set alpha. Anyone can help me ?
Thank you.
回答1:
There are several ways to color polylines. Google's iOS SDK documentation has good info on this.
The simplest way is to set the polyline's strokeColor
property:
polyline.strokeColor = [UIColor blueColor];
For more complex stuff, you'll want: GMSStyleSpan spanWithColor:(UIColor *)color
https://developers.google.com/maps/documentation/ios/reference/interface_g_m_s_style_span
They say to use spans
, even to set the entire line's color:
polyline.spans = @[[GMSStyleSpan spanWithColor:[UIColor redColor]]];
Alternating white/black every 500 "segments" (changes with zoom, maybe meters?):
NSArray *styles = @[[GMSStrokeStyle solidColor:[UIColor whiteColor]],
[GMSStrokeStyle solidColor:[UIColor blackColor]]];
NSArray *lengths = @[@(500), @(500)];
[polyline setSpans:GMSStyleSpans(polyline.path, styles, lengths, kGMSLengthRhumb)];
... useful for making your own train polylines, for example.
回答2:
Had the same problem with 1.7 version. Update to 1.8 (current).
来源:https://stackoverflow.com/questions/24102785/cannot-set-color-for-gmspolyline-with-google-map-sdk