简体   繁体   English

谷歌地图,地图不显示在HTML上

[英]Google maps, map doesn't show on html

This is my code 这是我的代码

<fieldset>
            <script src="https://maps.googleapis.com/maps/api/js"></script>
            <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>
            <div id="map_canvas"></div>
            <input type="submit" name="submit" class="submit action-button" value="Submit" />
        </fieldset>

as stated in this official tutorial 如本官方教程中所述

https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map https://developers.google.com/maps/tutorials/fundamentals/adding-a-google-map

but nothing on the HTML appears. 但HTML上没有任何内容出现。 I mean I see nothing where is the map? 我的意思是我什么都没看到地图? What am i missing please? 我错过了什么? I already added the load even 我已经加载了负载

From your code have you noticed the div tag: <div id="map_canvas"></div> You need an equivalent CSS style definition 从你的代码中你注意到div标签: <div id="map_canvas"></div>你需要一个等效的CSS样式定义

#map_canvas {
    width: 500px;
    height: 400px;
}

Here is a working example: http://jsfiddle.net/R8sdj/ 这是一个工作示例: http//jsfiddle.net/R8sdj/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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