简体   繁体   English

Android Google Maps SDK用虚线画一条折线

[英]Android Google maps SDK draw a polyline with a dashed line

I tried to find a way to draw a dashed line for the polyline I need in my application, but the only style parameters that PolyLineOptions allows you to change are: color and width. 我试图找到一种在应用程序中为折线绘制虚线的方法,但是PolyLineOptions允许您更改的唯一样式参数是:颜色和宽度。 I kept on searching on google and kept hearing of "Symbols" But as far as I understood this is only for Javascript. 我一直在Google上搜索,并不断听到“符号”,但据我了解,这仅适用于Javascript。 Is there a possibility to somehow draw the line for my polyline as a dashed line or dotted one? 是否有可能以某种方式将我的折线画成虚线或虚线? Also I've seen that on the iOS it is possible, should then android also have a similar function? 我也看到在iOS上有可能,然后android也应该有类似的功能吗?

In February 2017 Google released a new set of customizations for polylines and polygons in Google Maps Android API v2. 2017年2月,Google在Google Maps Android API v2中发布了一套新的针对折线和多边形的自定义设置。

See information about new features in the Shapes Guide . 请参阅“ 形状指南”中有关新功能的信息。 See an example in the Polylines and Polygons tutorial. 见一个例子中折线和多边形的教程。

You can also read the corresponding blog post here: 您还可以在此处阅读相应的博客文章:

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

I'm afraid this answer wont suit you: 恐怕这个答案不适合您:

Currently there is no easy way of doing this on Google Maps v2. 目前,在Google Maps v2上没有简单的方法可以做到这一点。 If you want to use the tools provided by Google you must split your Polyline in to several small ones, this SO question has a example: How to draw dashed polyline with android google map sdk v2? 如果要使用Google提供的工具,则必须将折线分割成几个小段,这样的问题有一个示例: 如何使用android google map sdk v2绘制虚线折线?

If you really want dashed lines and need to draw many (really many) I would suggest creating a overlay and draw on that instead and move it with the map. 如果您确实想要虚线并且需要绘制很多(确实很多),我建议您创建一个叠加层并在其上进行绘制,并随地图一起移动。 However it isn't an easy approach considering eg scaling and rotating of the map. 但是,考虑到地图的缩放和旋转,这不是一个容易的方法。 But for small - medium amount of dashed lines it is not worth the pain. 但是对于少量的虚线来说,这是不值得的。

There will likely be a dashed feature in Google Maps V3 considering that Google Maps JS v3 has it. 考虑到Google Maps JS v3具有此功能,Google Maps V3中可能会有一个破折号功能。

// 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM