我有一个map v2应用程序,能够从精确定位的位置绘制多段线到从gps获取的用户当前位置。
我使用谷歌方向来获取折线字符串。
绘图后在每条折线的终点处有一些不安。
查看实际设备的截图:
这是我的绘图代码:
for(int j = 0; j < allPoints.length - 1;j++) {
if(allPoints[j] != null) {
System.out.println("pontos " + allPoints[j]);
List<LatLng> test = decodePoly(allPoints[j]);
for (int i = 0; i < test.size() - 1; i++) {
LatLng src = test.get(i);
LatLng dest = test.get(i + 1);
try {
Polygon line = googleMap.addPolygon(new PolygonOptions()
.add(new LatLng(src.latitude, src.longitude),
new LatLng(dest.latitude, dest.longitude))
.strokeColor(Color.BLUE).geodesic(true));
} catch (NullPointerException e) {
Log.e("Error", "NullPointerException onPostExecute: " + e.toString());
} catch (Exception e2) {
Log.e("Error", "Exception onPostExecute: " + e2.toString());
}
}
}
}
我可以在每条折线后面放一个圆圈吗?它能解决我的问题吗?
答案 0 :(得分:1)
正如@Cheesebaron所述,最好的选择是只添加一个Polyline
。我没有测试过,因为我没有您的allPoints
数据的示例,但它可能是这样的:
for (int j = 0; j < allPoints.length - 1; j++) {
if (allPoints[j] != null) {
List<LatLng> test = decodePoly(allPoints[j]);
Polyline line = googleMap.addPolyline(new PolylineOptions().color(Color.BLUE).geodesic(true).addAll(test));
}
}
您还可以为每个Polyline
仅创建一个Polyline
而不是一个allPoints[j]
:
PolylineOptions polylineOptions = new PolylineOptions().color(Color.BLUE).geodesic(true);
for (int j = 0; j < allPoints.length - 1; j++) {
if (allPoints[j] != null) {
List<LatLng> test = decodePoly(allPoints[j]);
polylineOptions.addAll(test);
}
}
Polyline line = googleMap.addPolyline(polylineOptions);