0

我正在关注Google 提供的关于如何在 html 页面中使用简单地图的教程。但是,当我运行代码时,只显示一个灰色方块(我创建的 div)。任何人都可以帮助我吗?

这是我正在使用的代码:

<!DOCTYPE html>
<html>
    <head>
        <style>
            #map_canvas {
                width: 500px;
                height: 500px;
                background-color: #CCC;
            }
        </style>
        <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
        <script>
            function initialize() {
                var ap_canvas = document.getComputedStyle('map_canvas');
                var mapOptions = { new google.maps.Lating(44.5403, -78.5463),
                    zoom:8,
                    mapTypeld: google.maps.MapTypeId.ROADMAP }
                    var map = new google.maps.Map(map_canvas, mapOptions)
                    }
            google.maps.event.addDomListener(window, 'load', initialize);
        </script>
    </head>
    <body>
        <div id="map_canvas">

        </div>

    </body>
</html>
4

1 回答 1

1

你有几个错别字,例如“var ap_canvas”应该是“var map_canvas”。此功能有效:

<script>
function initialize() {
    var map_canvas = document.getElementById('map_canvas');
    var map_options = {
    center: new google.maps.LatLng(44.5403, -78.5463),
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(map_canvas, map_options)
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
于 2013-04-27T11:38:37.663 回答