【发布时间】:2016-06-28 08:36:51
【问题描述】:
在这里,我尝试使用 javascript 显示我的地图,但它显示的是灰色框而不是地图,并且在控制台中没有显示任何错误。
这是我的地图图片:
请帮忙解决。提前致谢。
这是我的代码:
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>
【问题讨论】:
-
我已经测试了您的代码并且它正在工作。你用的是什么类型的钥匙?检查此document,如果您将使用 Google Maps JavaScript API,则必须使用 浏览器密钥(一种 API 密钥)
-
当您在浏览器控制台中查看网络活动时,瓷砖请求的状态代码是什么?请求类似于google.com/maps/vt?....
标签: javascript c# html google-maps google-maps-api-3