2017-11-11 68 views
0
private void drawPolygon(List<LocationPointsModel> locationPoints, String fencingColor) { 

    mMap.clear(); 
    PolygonOptions rectOptions = new PolygonOptions(); 
    rectOptions.strokeColor(Color.parseColor(fencingColor)); 
    rectOptions.strokeWidth(2); 
    String fillcolor = Constants.FILL_COLOR_GEOFENCE + fencingColor.substring(1);//creating opacity less color 
    rectOptions.fillColor(Color.parseColor(fillcolor)); 
    LatLngBounds.Builder builder = new LatLngBounds.Builder(); 
    int size = locationPoints.size(); 
    for (int i = 0; i < size; i++) { 
     LatLng latLng = new LatLng(locationPoints.get(i).getLat(), locationPoints.get(i).getLon()); 
     latList.add(latLng); 
     rectOptions.add(latLng); 
    } 

    Polygon polygon = mMap.addPolygon(rectOptions); 
} 

在某些情況下,如果多邊形線相交,填充顏色未正確呈現。 Polygon Fill color Issue。可以用以下方式填充多邊形。 Desired output問題在地圖上繪製的多邊形的填充顏色

+0

此鏈接可能會幫助您https://developers.google.com/maps/documentation/android-api/polygon-tutorial – akhilesh0707

+0

問題是當多邊形線延伸到另一個多邊形線時繪製多邊形,否則它的罰款 –

回答

0

Google Maps Android API不支持自交多邊形的填充顏色。

有一個在谷歌問題跟蹤bug報告:

https://issuetracker.google.com/issues/35823225#comment15

註釋#15由谷歌代表國家發佈

我們不支持自相交多邊形(無論是輪廓或孔相交)

此外交叉多邊形和填充的問題是在文檔中提到。看看空心多邊形部分

如果孔與多邊形的輪廓相交,多邊形將被渲染而沒有任何填充。

https://developers.google.com/maps/documentation/android-api/shapes#create_a_hollow_polygon

貌似多邊形交集和灌裝不在地圖的Android API兼容。