Iam試圖找到給定座標所在的多邊形。錯誤:對象#<ui>沒有方法'containsLatLng'
下面是分析KML文件的代碼:
for (var i = 0; i < doc[0].placemarks.length; i++)
{
for(var j= 0; j<doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates.length; j++)
{
var poly_lat = doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates[j].lat;
var poly_lon = doc[0].placemarks[i].Polygon[0].outerBoundaryIs[0].coordinates[j].lng;
arr_cord[j] = new google.maps.LatLng(poly_lat,poly_lon);
//arr_cord[i] = poly_lat + "," + poly_lon;
//;
}
//alert(arr_cord);
arr_polyoptions[i] = { path: arr_cord,strokeColor: "#FF0000",strokeOpacity: 0.8,strokeWeight: 2,fillColor: "#0000FF",fillOpacity: 0.6 };
//polygons[i] = new google.maps.Polygon(cord_polyOptions);
styles[i] = doc[0].placemarks[i].styleID;
//alert(doc[0].placemarks.polygon.outerBoundaryis.LinearRing.coordinates);
}
現在通過多邊形檢查我用:
for(var curr = 0;curr<arr_polyoptions.length;curr++)
{
//var curr_polygon = polygons[curr];
console.log(arr_polyoptions[curr]);
var curr_polygon = new google.maps.Polygon(arr_polyoptions[curr]);
//var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
alert("isWithinPolygon = " + isWithinPolygon);
if(isWithinPolygon == 'true')
{
alert(styles[curr]);
break;
}
}
但代碼產生錯誤的對象#有沒有一種方法「containsLatLng 'on the line var isWithinPolygon = curr_polygon.containsLatLng(place.geometry.location);
有沒有人可以幫我解決這個問題?謝謝你在前進
日誌記錄的curr_polygon對象,結果在控制檯
ui
fillColor: "#0000FF"
fillOpacity: 0.6
gm_accessors_: Object
gm_bindings_: Object
latLngs: hg
b: Array[1]
0: hg
b: Array[2418]
[0 … 99]
0: N
jb: 41.8019457978553
kb: -87.62588976266039
如果它可以幫助
您是否嘗試過檢查Chrome控制檯中的內容?你應該能夠看到'curr_polygon'鍵 – Jacopofar
UI 填充顏色: 「#0000FF」 fillOpacity:0.6 gm_accessors_:對象 gm_bindings_:對象 latLngs:HG B:數組[1] 0:HG B:數組[2418] [0 ... 99] 0:N JB:41.8019457978553 KB:-87.62588976266039 – Arunu