当我加载时http://maps.google.com/maps/api/js?sensor=false http://maps.google.com/maps/api/js?sensor=false在脚本标签中,我在 Chrome、Safari、Firefox 和 IE9 中一切正常。
然而,当我在 IE9 中查看时在兼容模式下(或者,有人告诉我,在IE8)地图无法加载,并且控制台中会记录“'google'未定义”。
这是相关代码,其中触发错误的行用注释标识:
<html>
<head>
<title>Test Map</title>
<script type="application/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
</head>
<body>
<div id="map_canvas"></div>
<script type="text/javascript">
var lat=37.763154;
var lon=-122.457941;
var initialZoom=17;
var mapTypeId = 'Custom Map';
var mapStyle = [{featureType:"landscape", elementType:"all", stylers:[{hue:"#dae6c3"},{saturation:16},{lightness:-7}]},
{featureType:"road", elementType:"geometry", stylers:[{hue:"#ffffff"},{saturation:-100},{lightness:100}]}];
//**The error is tripped in this next line, again only in IE9 compatibility mode or IE8*
var styledMap = new google.maps.StyledMapType(mapStyle);
var mapType = new google.maps.ImageMapType({
tileSize: new google.maps.Size(256,256),
getTileUrl: function(coord,zoom) {
return "img/tiles/"+zoom+"/"+coord.x+"/"+coord.y+".png";
}
});
var map = new google.maps.Map(document.getElementById("map_canvas"),
{center:new google.maps.LatLng(lat,lon),
mapTypeId:google.maps.MapTypeId.ROADMAP,
zoom:initialZoom,
mapTypeControl:false});
map.overlayMapTypes.insertAt(0, mapType);
map.mapTypes.set(mapTypeId, styledMap);
map.setMapTypeId(mapTypeId);
</script>
</body>
</html>
因此,出于某种原因,仅在 IE9+ 兼容模式和 IE8 中,脚本标记指定http://maps.google.com/maps/api/js?sensor=false http://maps.google.com/maps/api/js?sensor=false在正文中的后续嵌入脚本之前不会加载和/或执行。
其他人可以复制吗?我该如何纠正这个问题?