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

Avijit
  • 3,834
  • 4
  • 33
  • 45
vikas
  • 3
  • 6

1 Answers1

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));
Olcay Ertaş
  • 5,987
  • 8
  • 76
  • 112
Pankaj
  • 2,115
  • 2
  • 19
  • 39
  • you can accept and upvote my answer so that others may refer to this answer for future help.thanx by the way!!! @vikas – Pankaj Apr 09 '14 at 07:18
  • 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 – vikas Apr 09 '14 at 07:26
  • you need to show some of your code at least otherwise it will be very painful for me to understand.@vikas – Pankaj Apr 09 '14 at 07:31
  • 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(); – vikas Apr 09 '14 at 07:52