使用Google Maps API发生Javascript错误
问题描述:
我使用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>
答
我试过你的代码发布在Dropbox上,并没有看到使用Safari 5.1(Lion)和Chrome 12.0.742的任何错误,也许你在缓存或你的网络上有问题k有一些问题,它没有正确地从谷歌下载javascript代码
我的2美分
这是什么奇怪的。有时候,如果我不断地清空Safari中的缓存并且相当/启动几次,它就会起作用。但通常我第一次从本地文件加载页面不会! –
咕噜它很奇怪我唯一的想法是某种网络错误,当你得到错误尝试在网络面板中看到的谷歌JavaScript的内容可能会出现错误,当你加载该代码 – wezzy