2011-08-01 134 views
0

我使用Google Maps API v3創建了一個簡單的靜態HTML頁面。這在一些瀏覽器(Windows XP上的IE v8)上工作正常,但我無法在Mac OS X 10.6.8和Windows XP上加載最新版本的Safari。我得到這些錯誤,當我打開Safari瀏覽器開發者控制檯上:使用Google Maps API發生Javascript錯誤

TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.Size(150,50)') 
TypeError: 'undefined' is not a constructor (evaluating 'new google.maps.LatLng(-30.2965590,153.1152650)') 

我已經把文件的副本在網上:

http://dl.dropbox.com/u/34923164/Errors_GoogleMaps.htm

這裏的HTML內容,以及:

<html> 
<head> 
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> 
<title>Google Maps Sample</title> 
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" /> 
<script type="text/javascript"> 
var map = null; 
function initialize() { 
var myOptions = { 
zoom: 13, 
center: new google.maps.LatLng(-30.2965590,153.1152650), 
mapTypeId: google.maps.MapTypeId.ROADMAP 
} 
map = new google.maps.Map(document.getElementById("map_canvas"), 
myOptions); 
google.maps.event.addListener(map, 'click', function() { 
infowindow.close(); 
}); 
var point = new google.maps.LatLng(-30.2965590,153.1152650); 
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/blue-dot.png'; 
var marker = createMarker(point,'Location: 33 Harbour Drive Coffs Harbour', icon) 
var point = new google.maps.LatLng(-30.2864430,153.1360230); 
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/red-dot.png'; 
var marker = createMarker(point,'Person: Fred Flinstone (108 Park Beach Road Coffs Harbour)') 
var point = new google.maps.LatLng(-30.2941737,153.1156785); 
var icon = 'http://www.google.com/intl/en_us/mapfiles/ms/icons/red-dot.png'; 
var marker = createMarker(point,'Person: Barney Rubble (108 Grafton St Coffs Harbour)') 
} 
var infowindow = new google.maps.InfoWindow(
{ 
size: new google.maps.Size(150,50) 
}); 
function createMarker(latlng, html, icon) { 
var contentString = html; 
var marker = new google.maps.Marker({ 
position: latlng, 
icon: icon, 
map: map, 
zIndex: Math.round(latlng.lat()*-100000)<<5 
}); 
google.maps.event.addListener(marker, 'click', function() { 
infowindow.setContent(contentString); 
infowindow.open(map,marker); 
}); 
} 
</script> 
</head> 
<body style="margin:0px; padding:0px;" onload="initialize()"> 
<div id="map_canvas"></div> 
</body> 
</html> 

回答

0

我試過你的代碼發佈在Dropbox上,並沒有看到使用Safari 5.1(Lion)和Chrome 12.0.742的任何錯誤,也許你在緩存或你的網絡上有問題k有一些問題,它沒有正確地從谷歌下載javascript代碼

我的2美分

+0

這是什麼奇怪的。有時候,如果我不斷地清空Safari中的緩存並且相當/啓動幾次,它就會起作用。但通常我第一次從本地文件加載頁面不會! –

+0

咕嚕它很奇怪我唯一的想法是某種網絡錯誤,當你得到錯誤嘗試在網絡面板中看到的谷歌JavaScript的內容可能會出現錯誤,當你加載該代碼 – wezzy