Draw polygon using onMarkerDrag google map v2

不羁的心 提交于 2019-12-12 03:11:50

问题


I'm trying to draw a free form lines over google map v2, so I'm trying to do this by listening to marker drag. I wrote the following code but it doesn't draw anything

@Override
public void onMarkerDrag(Marker marker) {
    Integer markerId = markerMapHash.get(marker);
    // as I'm giving every marker a key by HashMap 
    if (markerId == 1) {
        System.out.println("this is the draw line marker: "+marker.getPosition());
        lineCordinates.add(marker.getPosition());
        // lineCordinates is an arrayList

    }

    for (int i = 0; i < lineCordinates.size(); i++) {
        myMap.addPolygon(new PolygonOptions()
        .add(lineCordinates.get(i))
        .strokeColor(Color.RED));
    }

}

Could anyone help me in this issue? Thanks in advance


回答1:


I solved it using polyline instead of polygon

 myMap.addPolyline(new PolylineOptions()
        .addAll(lineCordinates)
        .width(5)
        .color(Color.RED));


来源:https://stackoverflow.com/questions/18297392/draw-polygon-using-onmarkerdrag-google-map-v2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!