问题
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