【问题标题】:Android Google maps SDK draw a polyline with a dashed lineAndroid 谷歌地图 SDK 用虚线绘制折线
【发布时间】:2014-07-30 12:41:22
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    // 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);
    

    【讨论】:

    • 这是唯一的解决方案。谢谢
    【解决方案3】:

    恐怕这个答案不适合你:

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

    如果您真的想要虚线并且需要绘制很多(真的很多),我建议您创建一个叠加层并在其上进行绘制,然后将其与地图一起移动。然而,考虑到地图的缩放和旋转,这不是一个简单的方法。但是对于中小数量的虚线来说,这是不值得的。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-14
      • 2015-09-14
      • 2014-03-19
      • 2013-07-02
      • 2023-04-06
      • 1970-01-01
      相关资源
      最近更新 更多