简体   繁体   English

谷歌地图显示灰色框而不是使用JavaScript的谷歌地图

[英]Google map showing gray box instead of google map using javascript

Here I am trying to display my map using javascript but its showing a gray box instead of map, and its not showing any error in console. 在这里,我尝试使用javascript显示地图,但显示的是灰色框而不是地图,并且在控制台中未显示任何错误。

Here is image of my map: 这是我的地图的图像:

在此处输入图片说明

Please help to solve it. 请帮助解决。 Thanks in advance. 提前致谢。

Here is my code: 这是我的代码:

 google.maps.event.addDomListener(window, 'load', init); function init() { var mapOptions = { zoom: 11, center: new google.maps.LatLng(40.767089, -73.969458), scrollwheel: false, disableDefaultUI: true, styles: [{ stylers: [{ hue: '#2c3e50' }, { saturation: 250 }] }, { featureType: 'road', elementType: 'geometry', stylers: [{ lightness: 50 }, { visibility: 'simplified' }] }, { featureType: 'road', elementType: 'labels', stylers: [{ visibility: 'off' }] }] }; var mapElement = document.getElementById('map_canvas'); var map = new google.maps.Map(mapElement, mapOptions); var marker = new google.maps.Marker({ position: map.getCenter(), map: map, title: 'Click to zoom' }); } 
 html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { margin: 0; padding: 0; position: absolute; } #map_canvas * { overflow: visible; } 
 <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MyKeyhere"></script> <div id="map_canvas" style="width: 600px; height: 600px; position: relative;"> </div> 

Not sure this helps: 不确定是否有帮助:

I am using a diffrent mapOptions on my website with mapTypeIds set. 我在设置了mapTypeIds的网站上使用了不同的mapOptions。

    var mapOptions = {
        zoom: 19,
        center: new google.maps.LatLng( 51.7734896,4.6764931),
        mapTypeControlOptions: {
            mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
        }
    };

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

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