2011-12-21 92 views
0

我很確定我的一切都正確。你能否爲我檢查一下。它給了我在控制檯這個錯誤:「未捕獲錯誤: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

什麼線你得到的錯誤? – 2011-12-21 21:40:00

+0

main.js,line 1 character 28 – 2011-12-21 21:42:43

+0

main.js從[link]獲取(maps.gstatic.com/cat_js/intl/ar_ALL/mapfiles/api-3/7/5) – 2011-12-21 21:44:43

回答

1

你犯同樣的錯誤兩次,缺少‘新’構造您的LatLng對象。

triangleCoords[i] = google.maps.LatLng(coords[s],coords[s+1]); 

應該

triangleCoords[i] = new google.maps.LatLng(coords[s],coords[s+1]); 

在中心1

var center1 = google.maps.LatLng(coords[0], coords[1]); 

也恰好應

var center1 = new google.maps.LatLng(coords[0], coords[1]); 
+0

非常感謝。我真的對代碼感到憤怒,因爲我多次閱讀它。我非常感謝你的幫助。再次感謝你。 – 2011-12-22 13:47:57

相關問題