0

how to make multiple polygon on Google Map I am using

List<lat long> data = new Array List<Lat Long>();

but its create only one polygon when we draw another then last polygon deleted so anyone please help me thanks in advance

1
  • Can you show more code?? Commented Apr 9, 2014 at 6:15

1 Answer 1

3

You can define a common method to draw polygon on google maps like this:

public PolygonOptions addPolygon(ArrayList < LatLng > arg) {

    LatLng[] data = arg.toArray();
    PolygonOptions polygonOptions;

    for (int i = 0; i <= data.length; i++) {
        polygonOptions = new PolygonOptions();
        polygonOptions.add(data[i], data[i + 1], data[i + 2])).strokeColor(Color.RED).strokeWidth(2);
        polygonOptions.fillColor(Color.parseColor("#51000000"));
        return polygonOptions;
    }
}

and then add it to your GoogleMap like this:

yourGoogleMap.addPolygon(addPolygon(data));
Sign up to request clarification or add additional context in comments.

4 Comments

you can accept and upvote my answer so that others may refer to this answer for future help.thanx by the way!!! @vikas
i am faced another problem when i make polygon clockwise its fine but when its clock+anticlockwise( Both Direction ) then stroke line will appear on fill color and the drawing spoiled
you need to show some of your code at least otherwise it will be very painful for me to understand.@vikas
for (int j = 0; j < maindata.size(); j++) { lines = new PolygonOptions(); Log.i("main", "maindata values " + maindata.get(j)); data = maindata.get(j); for (int i = 0; i < data.size(); i++) { lines.add(data.get(i)); lines.strokeWidth(3); lines.strokeColor(Color.TRANSPARENT); lines.fillColor(Color.parseColor("#51000000")); googlemap.addPolygon(lines); } } maindata.clear(); data.clear();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.