我在ie9中收到了这个错误,并且一直在拉我的头发。基本上“map-canvas”div不会加载。
这是我得到的完整错误:
SCRIPT5007:无法获取属性'offsetWidth'的值:object为null或undefined main.js,第29行,1104
任何帮助都将不胜感激!!
这是我的代码:
<!DOCTYPE html>
<html class="no-maps-mini" xmlns:v="urn:schemas-microsoft-com:vml">
<!-- Starts the HTML header area -->
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta content="text/html;charset=UTF-8" http-equiv="content-type"/>
<link rel="stylesheet" type="text/css" href="style/style.css" />
<title>Google Map Demo</title>
<script type="text/javascript"
src="http://maps.google.com/maps/api/js?sensor=false">
</script>
<script type="text/javascript">
var tableid1 = 4338356; //Fusion Table ID
var mylatlng = new google.maps.LatLng(49.66685, -124.91038); //map centre - Courtenay/Comox
function initialize() {
var myOptions = {
scaleControl: true,
overviewMapControl: true,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DEFAULT
},
zoom: 14,
center: mylatlng,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);
var layer1 = new google.maps.FusionTablesLayer({
query: {
select: "'geometry'",
from: tableid1
},
map: map
});
};
function changeMapl() {
var searchString = document.getElementById('search-string-l').value.replace(/'/g, "\\'");
layerl.setOptions({
query: {
select: "'geometry'",
from: tableid1,
where: "'Name' = '" + searchString + "'"
}
});
};
google.maps.event.addDomListener(window, 'load', initialize());
</script>
</head>
<body>
<div id="container">
<div id="header">
<h1>Comox Valley Walking Trails</h1>
<hr />
</div><!-- end #header -->
<div id="content-secondary">
<h3>sidebar1 Content</h3>
<h4>Trails</h4>
<select id="search-string-l" onChange="changeMapl(this.value);">
<option value="">--Select--</option>
<option value="MacDonald Wood Park">MacDonald Wood Park</option>
<option value="Goose Spit">Goose Spit</option>
<option value="Mack Laing Park">Mack Laing Park</option>
<option value="Filberg Rd to Goose Spit">Filberg Rd to Goose Spit</option>
</select>
<div class="clear"></div>
</div>
<div id="content-primary"><div id="map-canvas"></div></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats -->
<br class="clearfloat" />
<div id="footer">
<p>Footer</p>
<!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
答案 0 :(得分:0)
这是我在IE8中遇到的错误:
网页错误详情
消息:'null'为null或不是对象 行:29 查尔:1104 代码:0 URI:http://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/7a/main.js
您有几个问题:
google.maps.event.addDomListener(window,'load',initialize()); 不正确,你需要将其更改为 google.maps.event.addDomListener(window,'load',initialize); 它的方式(用括号)它在定义map div之前执行,导致上面的错误。)
(图层后跟小写字母“L”)与layer1(图层后跟第一个图层)不同。
在你发布的代码中,map-canvas div没有大小(对于你的版本可能不是这样)