I want to create a regular polygon shape no matter the order of click on map. Currently I am facing a problem if a click on the map to draw polygon in the following manner then it works fine order is following
top left top right bottom right bottom left. IF this order is maintained then polygon drawn is perfectly fine similarly if i click on top right ,top left bottom right bottom it is also drawing perfectly fine. If when I change a single pint in order it does not draw proper shaped polygon
Image1
Code 2 draw polygon is following
gMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
llClearSelection.setVisibility(View.VISIBLE);
gMap.addMarker(new MarkerOptions().anchor(0.5f, 0.5f).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)).position(latLng));
if (markerClicked) {
// latLngArrayListPolygon.clear();
if (polygon != null) {
polygon.remove();
polygon = null;
}
polygonOptions.add(latLng);
latLngArrayListPolygon.add(latLng);
polygonOptions.strokeColor(Color.RED);
polygonOptions.fillColor(shadeColor);
polygon = gMap.addPolygon(polygonOptions);
if (latLngArrayListPolygon.size() > 1)
ivSaveMap.setVisibility(View.VISIBLE);
else
ivSaveMap.setVisibility(View.GONE);
} else {
if (polygon != null) {
polygon.remove();
polygon = null;
}
polygonOptions = new PolygonOptions().add(latLng);
latLngArrayListPolygon.add(latLng);
markerClicked = true;
}
}
});
My concern is I want to draw a regular shape irrespective of the order of click on map