在地图v2中折线末尾不安

时间:2016-10-07 09:28:20

标签: android google-maps

我有一个map v2应用程序,能够从精确定位的位置绘制多段线到从gps获取的用户当前位置。

我使用谷歌方向来获取折线字符串。

绘图后在每条折线的终点处有一些不安。

查看实际设备的截图:

enter image description here

这是我的绘图代码:

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());
                   }

               }
           }

        }

我可以在每条折线后面放一个圆圈吗?它能解决我的问题吗?

1 个答案:

答案 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);