【问题标题】:Google map showing gray box instead of google map using javascript谷歌地图显示灰色框而不是使用javascript的谷歌地图
【发布时间】: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


【解决方案1】:

不确定这是否有帮助:

我在我的网站上使用不同的 mapOptions 并设置了 mapTypeIds。

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

【讨论】:

  • 但它不能帮助制作可能的地图样式
  • 也许查看我网站上的代码有帮助?我自己在 google.maps 上使用自定义主题样式:edwardpieper.nl/?c=contact
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-16
  • 2011-02-08
  • 1970-01-01
  • 1970-01-01
  • 2012-11-11
相关资源
最近更新 更多