0

The code below doesn't work with Google Maps API v2. The polygons (outer and inner polygons) are drawn with the right border, but the fill color of the outer one is not drawn.

PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.add(outerCoordinates);
polygonOptions.addHole(Arrays.asList(innerCoordinates));
polygonOptions.fillColor(Color.BLUE);
polygonOptions.strokeWidth(1.0f);

Does anybody face the same problem?

4

2 回答 2

2

Check whether there is a requirement that polygon coordinates have to be clockwise (or counterclockwise) ordered. Try to change the order.

于 2013-01-06T18:20:12.873 回答
0

The vertices must be added in counterclockwise order. Reference

I wrote a function to determinate if a List<LatLng> is clockwise. The code is an implementation of this answer:

public boolean isClockwise(List<LatLng> region) {
    final int size = region.size();
    LatLng a = region.get(size - 1);
    double aux = 0;
    for (int i = 0; i < size; i++) {
        LatLng b = region.get(i);
        aux += (b.latitude - a.latitude) * (b.longitude + a.longitude);
        a = b;
    }
    return aux <= 0;
}

Before adding the polygon points put these three lines:

if (isClockwise(polygon)) {
    Collections.reverse(polygon);
}
于 2013-01-18T15:51:59.417 回答