简体   繁体   中英

Cannot set the marker on a google map

<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>

Here is live example: http://travel.demas.me Why can't I see the marker?

I'm seeing this error through Chrome's Developer Tools:

travel.demas.me:14 Uncaught TypeError: Cannot set property 'innerHTML' of null

On this line:

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

Try removing this for debugging purposes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM