Hello everyone,
I am using Google map V2 and I have to draw a shape on the map fragment by touching it. i.e if I rotate my fingers on the map a shape should be generat
I have done it using the map's OnMapClickListener:
private boolean drawing = false;
private Polygon polygon;
private List points = new ArrayList<>();
public class AreasFragment extends mapFragment implements GoogleMap.OnMapClickListener {
@Override
public void onMapClick(LatLng point) {
points.add(point);
if(!drawing) {
map.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag))
.anchor(0.2f, 1.0f)
.position(point));
PolygonOptions rectOptions = new PolygonOptions()
.strokeWidth(2)
.fillColor(0x80000000)
.add(point);
polygon = map.addPolygon(rectOptions);
drawing = true;
}
else {
polygon.setPoints(points);
}
}
}