【发布时间】:2020-01-21 18:46:37
【问题描述】:
[在此处输入图片描述]
1我想在 android 中使用地图框绘制虚线以向用户显示路线。当我单击标记时,类似于该图像的内容应该显示该虚线。
【问题讨论】:
-
这个答案展示了如何绘制虚线:stackoverflow.com/a/47687938/2383176 可能会帮助您设置线条图层的样式。
[在此处输入图片描述]
1我想在 android 中使用地图框绘制虚线以向用户显示路线。当我单击标记时,类似于该图像的内容应该显示该虚线。
【问题讨论】:
一个标记只需要一个 LatLng 点信息,因此它工作得很好。但是,一条线连接两个或多个点,折线连接两个或多个连续点。在您的代码中,您只放了一个点,这甚至不足以制作一条(多段)线。您需要向 PolylineOptions 添加更多点,如下例所示:
ArrayList<LatLng> points = new ArrayList<>();
// add two or more different LatLng points
points.add(new LatLng(-7.955, 112.613));
points.add(new LatLng(-7.956, 112.616));
points.add(new LatLng(-7.958, 112.619));
// or add from other collections
for(TrackPoint trackPoint: this.trackPoints)
points.add(new LatLng(trackPoint.latitude, trackPoint.longitude));
// create new PolylineOptions from all points
PolylineOptions polylineOptions = new PolylineOptions()
.addAll(points)
.color(Color.RED)
.width(3f);
// add polyline to MapboxMap object
this.mapboxMap.addPolyline(polylineOptions);
希望这会有所帮助。
【讨论】: