android - How to draw smooth(lines connected without any breaks) lines over google map in Android?
问题描述
I am building a path tracing application on Android. This particular activity will receive position and whenever I get a position, I will join the last point with the current point. With this, I am getting the path but it is not smooth at joints.
A is something I am getting. B is what I am trying to achieve.
A
________________
|________________
| |
| |
B
________________
|________________
| |
| |
The problem is because I draw lines with 2 points. When google draws 3 points, the joint is connected properly. I am looking for a way something other than drawing 3 points instead of 2.
I am adding points to polyline
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.add(lastPosition);
polylineOptions.add(currentPosition);
polylineOptions.color(Color.BLUE);
polylineOptions.width(8);
mMap.addPolyline(polylineOptions);
I also tried to set polylineOptions.jointType(JointType.ROUND) but not much improvement.
解决方案
JointType
影响一条折线的线段,而不是单独的折线。所以不要用两点线绘制路径 - 将整个路径绘制为一条折线。像这样的东西:
// add polyline to map (once) and save reference to it in polyLine variable
PolylineOptions polylineOptions = new PolylineOptions();
polylineOptions.add(lastPosition);
polylineOptions.add(currentPosition);
polylineOptions.color(Color.BLUE);
polylineOptions.width(8);
Polyline polyLine = mMap.addPolyline(polylineOptions);
...
// every time when currentPosition updated
List<LatLng> polyLinePoints = polyLine.getPoints(); // get polyline points
polyLinePoints.add(currentPosition); // add currentPosition to polyline points
polyLine.setPoints(polyLinePoints); // update polyline points
推荐阅读
- reactjs - 添加图层时,底图上的 Mapbox 单击侦听器失败
- javascript - 将所有数据导出到 Excel,包括来自分页的数据
- php - 注销时如何更改我的帐户菜单 Woocommerce 的链接
- python - 在 python 中为大数据集绘制时间序列的正确白天格式是什么?
- mysql - MySQL Window 函数计算百分比
- javascript - 如何从由斜杠分隔的 url 中获取 url 参数,例如 http://myweb.com/example/12345/222/4444 我想从上面的 url 中获取 12345、222、4444
- java - tomcat 7 到 9 迁移:java.lang.IllegalArgumentException:指定的主资源集 [...] 无效
- javascript - 引导日期时间选择器未打开
- magento - magento 2.3 安装后黑屏
- python - 从 Music21 保存图像文件