build.gradle
中,您需要添加:dependencies {
compile 'com.google.android.gms:play-services-maps:10.2.0'
}
您可以指定折线的描边样式,但无法更改颜色,因此您需要在实心折线上绘制虚线折线以达到所需的图案(请注意,您将绘制两个折线而不是一个,这可能会影响性能):
List<LatLng> latLngs = new ArrayList<>();
// Add all your LatLngs to the List
// Draw a solid green polyline
mMap.addPolyline(new PolylineOptions()
.addAll(latLngs)
.color(Color.GREEN));
// Draw a dashed (60px spaced) blue polyline
List<PatternItem> dashedPattern = Arrays.asList(new Dash(60), new Gap(60));
mMap.addPolyline(new PolylineOptions()
.addAll(latLngs)
.pattern(dashedPattern)
.color(Color.BLUE));
结果如下图所示:
您可以在此处找到有关新样式折线功能的更多信息。
Random rnd = new Random();
int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256));
---循环每个纬度和经度并添加----
mMap.addPolyline(new PolylineOptions()
.add(new LatLng(lats, lons), new LatLng(late,lone))
.width(5)
.color(color));
根据您的要求更改颜色编码