我设法在地图上绘制一个多边形。我使用的代码:
private void drawPolygons() {
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.addAll(arrayPolygon);
polygonOptions.strokeColor(Color.CYAN);
polygonOptions.strokeWidth(4);
polygonOptions.fillColor(Color.CYAN);
Polygon polygon = googleMap.addPolygon(polygonOptions);
}
我想画另一个。我试过这样:
private void drawPolygons() {
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.addAll(arrayPolygon);
polygonOptions.addAll(arrayPolygonSecond);
polygonOptions.strokeColor(Color.CYAN);
polygonOptions.strokeWidth(4);
polygonOptions.fillColor(Color.CYAN);
Polygon polygon = googleMap.addPolygon(polygonOptions);
}
这两个LatLng阵列刚搞砸了(两个阵列的顶点都已连接)。我需要将这两个多边形分开。
任何帮助都会受到很多赞赏。谢谢你的推荐。
答案 0 :(得分:1)
找到解决方案。我不得不做两个独立的功能。这是代码:
private void drawPolygons() {
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.addAll(arrayPolygonOne);
polygonOptions.strokeColor(Color.CYAN);
polygonOptions.strokeWidth(4);
polygonOptions.fillColor(Color.CYAN);
Polygon polygon = googleMap.addPolygon(polygonOptions);
}
private void drawPolygonsOne() {
PolygonOptions polygonOptions = new PolygonOptions();
polygonOptions.addAll(arrayPolygonOne);
polygonOptions.strokeColor(Color.CYAN);
polygonOptions.strokeWidth(4);
polygonOptions.fillColor(Color.CYAN);
Polygon polygon = googleMap.addPolygon(polygonOptions);
}
答案 1 :(得分:0)
这是我的代码,动态绘制多个多边形区域:
List<LatLng> allArea;
for(HeadArea area : data.getListHeadAreas()) {
allArea = new ArrayList<>();
for(DetailArea detailArea : area.getDetailAreas()) {
allArea.add(new LatLng(detailArea.getLatitude(), detailArea.getLongitude()));
}
mMap.addPolygon(new PolygonOptions()
.addAll(PolyUtil.simplify(allArea, 3))
.fillColor(Color.RED)
.strokeColor(Color.BLUE)
.strokeWidth(3));
}