2013-05-21 63 views
0

好的,我在加載地圖時遇到了這個問題,這部分將顯示「google」爲undefined谷歌地圖加載錯誤「谷歌」undefined

var polyline = [ 
    new Google.map.LatLng(3.032617, 101.376), 
    new Google.map.LatLng(3.03255, 101.3759), 
    new Google.map.LatLng(3.032467, 101.3758), 
    new Google.map.LatLng(3.031867, 101.3753), 
    new Google.map.LatLng(3.0318, 101.3753) 
]; 

var polylineopts = { 
    path: polyline, 
    map: map, 
    strokecolor: 'blue', 
    strokeopacity: 1.6, 
    strokeweight: 3, 
    geodesic: true 
}; 

var poly = new google.maps.Polyline(polylineopts); 
+3

是U包括在頭部即谷歌地圖的js'' –

+0

在這段代碼中沒有任何理由google'would not'undefined'。你爲什麼認爲它不應該? –

+0

你有意使用'var poly = new Google.maps.Polyline(polylineopts);'(大寫)? –

回答

2

我預計錯誤是「Google」是未定義的。 Javascript是區分大小寫的。

應該是:

var polyline = [ 
    new google.maps.LatLng(3.032617, 101.376), 
    new google.maps.LatLng(3.03255, 101.3759), 
    new google.maps.LatLng(3.032467, 101.3758), 
    new google.maps.LatLng(3.031867, 101.3753), 
    new google.maps.LatLng(3.0318, 101.3753) 
]; 

var polylineopts = { 
    path: polyline, 
    map: map, 
    strokecolor: 'blue', 
    strokeopacity: 1.6, 
    strokeweight: 3, 
    geodesic: true 
}; 

var poly = new google.maps.Polyline(polylineopts); 

working example