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

标签 javascript html google-maps-api-3


我正在使用 3.8 版 ,但没有 key 。我以前在我的桌面上使用过这个确切的代码(没有 key ),它工作得很好,但现在由于某种原因它不工作了。

我找不到任何拼写错误,没有 key 的导入声明是否与我正在使用的有所不同?

这是我的精简代码:

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

最佳答案

它正在工作。也许您忘记为 map div 提供 width/height,所以您看不到它?

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

关于javascript - 为什么这个简单的谷歌地图代码不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854191/

相关文章:

javascript - infowindow.setContent 和 OverlappingMarkerSpiderfier 有问题

javascript - 成功后VueJs清晰的表格

Javascript createElement,添加html元素和简单文本

javascript - Node.js 代码未在 javascript 函数中运行

javascript - 使表格单元格不会因为内容而垂直扩展

javascript - 滚动时更改导航栏固定顶部颜色

javascript - Google Maps API v3 信息窗口关闭事件/回调?

c# - 在jquery中加载大数据

javascript - 如何更改 jQuery DataTables 输入行为

google-maps - 让所有街道在 Google map 视口(viewport)中可见