【发布时间】:2020-12-15 15:03:48
【问题描述】:
我正在使用Google Maps 开发应用程序,我想更改地图上polyline 的样式。我想将折线的颜色更改为渐变线,如何在 Android 中执行此操作。
【问题讨论】:
标签: google-maps google-maps-android-api-2
我正在使用Google Maps 开发应用程序,我想更改地图上polyline 的样式。我想将折线的颜色更改为渐变线,如何在 Android 中执行此操作。
【问题讨论】:
标签: google-maps google-maps-android-api-2
你可以使用我的richmaps库:https://github.com/antoniocarlon/richmaps
您可以像这样轻松创建渐变折线:
RichPolylineOptions polylineOpts = new RichPolylineOptions(null)
.zIndex(3) // zIndex represents the position of the polyline on the RichLayer
.strokeWidth(15)
.strokeColor(Color.YELLOW) // Set the polyline base color
.linearGradient(true)
.add(new RichPoint(new LatLng(40.22987, -3.95931)).color(Color.RED)) // Set color for some vertices
.add(new RichPoint(new LatLng(40.23109, -3.95926)))
.add(new RichPoint(new LatLng(40.23063, -3.95837)).color(Color.RED))
.add(new RichPoint(new LatLng(40.23169, -3.95809)))
.add(new RichPoint(new LatLng(40.23093, -3.95705)))
.add(new RichPoint(new LatLng(40.23023, -3.95626)));
RichPolyline polyline = polylineOpts.build();
polyline.add(new RichPoint(new LatLng(40.23163, -3.95602)).color(Color.CYAN)); // RichPoint added after the creation of the RichPolyline
richLayer.addShape(polyline);
【讨论】:
我一直在研究一个用例,用于在 Android 的 Google Maps 上创建渐变折线,因为它不是 Google Maps Android SDK 中的内置 API。
因此,我创建了一个 Github 存储库,用于讨论用例、我采用的方法以及我如何实现它以在 Android 中的 Google 地图上显示渐变折线。
如果您对此类主题感兴趣,请查看并随时联系或贡献:)
【讨论】:
在 Google Maps SDK 3.1.0(测试版)中可用:https://developers.google.com/maps/documentation/android-sdk/v310-beta#creating_a_gradient_polyline
【讨论】:
如果您正在寻找准确的绘图和跟踪,您可以给this library 一个机会
【讨论】: