我很确定我的一切都是正确的。你可以帮我查一下吗?它在控制台中给出了这个错误:“未捕获错误:0值不正确(从另一种语言翻译)”
function map_load() {
var draw;
var coords = Array(23.078412614088098, 57.33448100333726,
23.07858534246487, 57.33415377383744,
23.078234950383354, 57.33415913825547,
23.078190534420507, 57.334582927279826,
23.07792403833525, 57.3352266574434);
var s = -2;
var triangleCoords = [];
var coords_num = coords.length/2;
for (i = 0; i < coords_num ; i++) {
s += 2;
triangleCoords[i] = google.maps.LatLng(coords[s],coords[s+1]);
}
var center1 = google.maps.LatLng(coords[0], coords[1]);
if (coords.length > 1) {
draw = new google.maps.Polygon({
paths: triangleCoords,
strokeColor: "#FF0000",
strokeOpacity: 0.8,
strokeWeight: 2,
fillColor: "#FF0000",
fillOpacity: 0.35
});
} else {
draw = new google.maps.Marker({
position: triangleCoords,
title:"your item location"
});
}
var myOptions = {
zoom: 16,
center: center1,
panControl:false,
streetViewControl:false,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
draw.setMap(map);
}
答案 0 :(得分:1)
你犯了同样的错误两次,错过了“new”这个词来构建你的LatLng对象。
triangleCoords[i] = google.maps.LatLng(coords[s],coords[s+1]);
应该是
triangleCoords[i] = new google.maps.LatLng(coords[s],coords[s+1]);
同样发生在center1
var center1 = google.maps.LatLng(coords[0], coords[1]);
应该是
var center1 = new google.maps.LatLng(coords[0], coords[1]);