2

我在 ie9 中遇到了这个错误,并且一直在拔头发。基本上“地图画布” div 不会加载。

这是我得到的完整错误:

SCRIPT5007:无法获取属性“offsetWidth”的值:对象为 null 或未定义 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>
4

1 回答 1

0

这是我在 IE8 中遇到的错误:

网页错误详情

消息:'null' 为空或不是对象行:29 字符:1104 代码:0 URI:http ://maps.gstatic.com/intl/en_us/mapfiles/api-3/9/7a/main.js

你有几个问题:

  1. google.maps.event.addDomListener(window, 'load', initialize()); 不正确,需要改成 google.maps.event.addDomListener(window, 'load', initialize); 在定义地图 div 之前执行它的方式(带括号),导致上面的错误)。

  2. 在 ChangeMap1 中,layerl(layer 后跟小写“L”)与 layer1(layer 后跟数字一)不同。

  3. 在您发布的代码中,地图画布 div 没有大小(您的版本可能不是这样)

链接到工作版本

于 2012-06-29T05:05:22.017 回答