Cannot set color for GMSPolyline with Google Map SDK

雨燕双飞 提交于 2019-12-24 00:57:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!