无法在Google地图上设置标记

时间:2011-04-26 10:45:57

标签: javascript google-maps-api-2

<script src='http://maps.google.com/maps?file=api&v=2&key=ABQIAAAATB4WHBfI6bn_r2yHC5-cShQUwb554zi4F9w6VUOuAIqhCjZSuhSasJwxZuyueyW2ctbO3M8TQaJBIA' type='text/javascript'></script><script type='text/javascript'>
      //<![CDATA[
      function load() {
        if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById('map'));
            GEvent.addListener(map, 'moveend', function() {
                var center = map.getCenter();
                document.getElementById('message').innerHTML = center.toString();
            });

                    map.addControl(new GSmallMapControl()); // 
                    map.addControl(new GMapTypeControl()); // 
                            map.setCenter(new GLatLng(55.752,37.616), 10);

                    var Moscow_point = new GLatLng(55.752,37.616);
                    var Moscow = new GMarker(Moscow_point, {title: 'Moscow'});
                    map.addOverlay(Moscow);
                }
      }
      //]]>
</script>  

</head>

<body  onload='load()' onunload='GUnload()'>
   <div id='map' style='width: 100%; height: 300px'></div> 
</body>

以下是实例:http://travel.demas.me 为什么我看不到标记?

1 个答案:

答案 0 :(得分:1)

我通过Chrome的开发人员工具看到了这个错误:

  

travel.demas.me:14未捕获TypeError:无法设置属性'innerHTML'为null

在这一行:

document.getElementById('message').innerHTML = center.toString();

尝试将其删除以进行调试。