[英]How can i pass values of latlng array list to polygon
我將坐標存儲在Firebase中。 並且總是以latlng類型的arraylist檢索。 我的問題是如何將坐標的數組值傳遞給polygonpolygon。
這是我嘗試過的。
private void DrawPolygon(List<LatLng> array) {
int length = array.size();
// Store a data object with the polygon,
// used here to indicate an arbitrary type.
PolygonOptions poly = new PolygonOptions();
for (int i = 0; i < length; i++) {
poly.add(new LatLng(array.get(i).latitude, array.get(i).longitude));
}
}
在運行時,不填充多邊形數組。
在嘗試填充多邊形之前,應檢查數組的有效性。 可能是引用數組中的值為空。
private void DrawPolygon(List<LatLng> array) {
int length = array.size();
// Store a data object with the polygon,
// used here to indicate an arbitrary type.
PolygonOptions poly = new PolygonOptions();
for(int i = 0; i < length; i++){
if(array.get(i).latitude != null &&
array.get(i).longitude != null){
LatLng latLong = new LatLng(array.get(i).latitude,
array.get(i).longitude);
poly.add(latLong);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.