【问题标题】:How to draw dotted line in android using map Box如何使用地图框在android中绘制虚线
【发布时间】:2020-01-21 18:46:37
【问题描述】:

[在此处输入图片描述]

1我想在 android 中使用地图框绘制虚线以向用户显示路线。当我单击标记时,类似于该图像的内容应该显示该虚线。

【问题讨论】:

标签: android mapbox


【解决方案1】:

一个标记只需要一个 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);

希望这会有所帮助。

【讨论】:

  • 我认为“虚线”是指带有点和间隙样式的线,而不是点线
【解决方案2】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多