Android Google地图SDK使用虚线绘制折线

时间:2014-07-30 12:41:22

标签: android google-maps maps line google-polyline

我试图在我的应用程序中找到一种为我需要的折线绘制虚线的方法,但PolyLineOptions允许您更改的唯一样式参数是:颜色和宽度。 我继续在谷歌上搜索,并一直听到"符号"但据我所知,这仅适用于Javascript。是否有可能以某种方式将我的折线绘制为虚线或虚线? 另外我已经看到iOS上有可能,那么Android应该有类似的功能吗?

3 个答案:

答案 0 :(得分:3)

2017年2月,Google在Google Maps Android API v2中发布了一系列针对折线和多边形的自定义。

查看Shapes Guide中有关新功能的信息。请参阅“折线和多边形”教程中的example

您还可以在此处阅读相应的博文:

https://maps-apis.googleblog.com/2017/02/styling-and-custom-data-for-polylines.html

答案 1 :(得分:1)

我担心这个答案不适合你:

目前在谷歌地图v2上没有简单的方法。如果您想使用Google提供的工具,您必须将您的折线分成几个小的,这个SO问题有一个例子:How to draw dashed polyline with android google map sdk v2?

如果你真的想要虚线并且需要绘制很多(真的很多),我会建议创建一个叠加并在其上绘制,然后用地图移动它。然而,考虑到例如缩放和旋转地图,这不是一种简单的方法。但对于中等数量的虚线,这不值得痛苦。

考虑到Google Maps JS v3,谷歌地图V3中可能会有一个虚线功能。

答案 2 :(得分:0)

// Set a Stroke pattern [Add dots dashes and spaces as per your requirement]
List<PatternItem> pattern = Arrays.<PatternItem>asList(new Dot(), new Gap(20), new Dash(30), new Gap(20));

// Intialize PolylineOptions
PolylineOptions lineOptions = new PolylineOptions();

// set the pattern to polylineOptions like you set color,width etc.
lineOptions.setPattern(pattern);

// Add the polyline to map passing PolylineOptions
map.addPolyline(lineOptions);