-1
尝试在我的页面上显示Google地图时出现此错误。 “JavaScript运行时错误:无法获取未定义或空引用的属性'offsetWidth'”尝试显示Google地图时出现“偏离度”错误
它来自Javascript函数初始化()从行var map = new google.maps.Map(document.getElementById(“地图画布“)
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8
};
var map = new google.maps.Map(document.getElementById("map-canvas"),
mapOptions);
}
google.maps.event.addDomListener(window, 'load', initialize);
这里是我的html
<div id="map-canvas">
<h2>hello</h2>
</div>
,这里是我的CSS
#map-canvas {
position: fixed;
top: 41px;
left: 0;
bottom: 0;
width: 40%;
height: 100%;
background-color: pink;
/*border: 3px solid black;*/
}
我得到了显示的地图没有问题。当div id与'getElementById()'中提供的字符串不同时,通常会显示此错误。你有哪个浏览器? –
我明白了。我不得不使用Chrome。它仍然在IE中破碎。有谁知道为什么? – user1186050
你需要在Chrome中做什么?你能提供一个演示这个问题的小提琴吗? – geocodezip