为什么这个简单的谷歌地图代码不起作用




我使用的是没有密钥的 3.8 版。我之前在桌面上使用过这个确切的代码(没有密钥),它工作得很好,但现在由于某种原因它不起作用。
我找不到任何拼写错误,没有密钥的导入声明是否与我正在使用的声明发生了变化?
这是我精简的代码:

<!DOCTYPE html>
<html>
    <head>
        <title>asdfasdf</title>
    </head>
    <body onload = "initialize();">
        <!-- map here -->
        <div id = "map"></div>
        <!-- Google Maps API -->
        <script type = "text/javascript" src = "http://maps.googleapis.com/maps/api/js?&amp;sensor=true&amp;v=3.8"></script>
        <script type = "text/javascript">
            function initialize()
            {
                // object literal for map options
                var myOptions =
                {
                    center: new google.maps.LatLng(37.09024, -95.712891), // coordinates for center of map 30, 3
                    zoom: 4, // smaller number --> zoom out
                    mapTypeId: google.maps.MapTypeId.HYBRID // ROADMAP, SATELLITE, TERRAIN, or HYBRID
                };
                // note: if the id has a dash in its' name, map instantiation doesn't work!
                var map = new google.maps.Map(document.getElementById("map"), myOptions);
            } // end of initialize
        </script>
    </body>
</html>

它正在工作。 也许你忘了给你地图div width/height所以你看不到它?

你可以看看这里 http://jsfiddle.net/2HmMQ/

V3.8 已停用,如果您请求它,您将获得 v3.9。

您的

问题是您的地图没有大小,因此您看不到它。

如果我更改您的地图div 以赋予它大小,如下所示:

        <div id="map" style="height:500px; width:600px;"></div>

它有效。

最新更新