gpt4 book ai didi

javascript - Google Maps API 加载失败 ("' google' is undefined") in IE8

转载 作者:数据小太阳 更新时间:2023-10-29 04:37:36 24 4
gpt4 key购买 nike

当我加载 http://maps.google.com/maps/api/js?sensor=false 时在脚本标签中,我在 Chrome、Safari、Firefox 和 IE9 中一切正常。

但是,当我在 兼容模式 中查看 IE9(或者,有人告诉我,在 IE8 中)时, map 不会加载并且“'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不会在主体中的后续嵌入式脚本之前加载和/或执行。

其他人能复制吗?我该如何解决这个问题?

最佳答案

显然,问题在于 IE 8 无法理解“application/javascript”。我在 <script> 中将其更改为“text/javascript” <head> 中的标签部分,现在我的代码可以工作了。当然,如果我将它改回“application/javascript”,它就会停止工作。

关于javascript - Google Maps API 加载失败 ("' google' is undefined") in IE8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6335019/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com