简体   繁体   English

Google地图“缩放”和平移按钮未显示! 这肯定不是css问题

[英]Google maps Zoom and Pan buttons not showing! And it is not a css issue for sure

I have a google map on my site and the map zoom and pan buttons are not displaying. 我的网站上有一张Google地图,并且地图的缩放和平移按钮没有显示。 I added css 我加了css

Here are my Map options: 这是我的地图选项:

var mapOptions = {
    center : new google.maps.LatLng(22.491629,83.901082),
    zoom : 6,
    minZoom : 6,
    panControl:true,
    zoomControl:true,
    mapTypeControl:true,
    scaleControl:true,
    streetViewControl:true,
    overviewMapControl:true,
    rotateControl:true,
    zoomControlOptions : {
      position : google.maps.ControlPosition.RIGHT_CENTER
    },
    panControlOptions : {
      position : google.maps.ControlPosition.LEFT_TOP,
    },
    mapTypeId : google.maps.MapTypeId.TERRAIN,
    // styles : mapStyle,
  }

var mapElement = document.getElementById('map'); 
map = new google.maps.Map(mapElement, mapOptions);

And here is the CSS i have seen on other stackexchange answers, but not working for me 这是我在其他stackexchange答案上看到的CSS,但对我不起作用

<style>
  #mapholder img {
    max-width: none !important;
  }
  #map img { max-width: none !important; }
  /* IE 6 does not support max-width so default to width 100% */
  .ie6 img {
      width:100%;
  }
  .gm-style img { max-width: none !important; }
  .gm-style label { width: auto !important; display: inline; }
</style>

And the HTML for the map 还有地图的HTML

<div id="mapholder">
  <div id="map"></div>
</div>

I think it may be because you have not initialised the map to run, so it will not display. 我认为可能是因为您尚未初始化要运行的地图,所以它不会显示。

You can do this by adding this line of code to your javascript: 您可以通过将以下代码行添加到javascript中来实现此目的:

google.maps.event.addDomListener(window, 'load', initialize);

and putting your map options in an initialise function. 并将地图选项置于initialise函数中。

Here is a working example: http://codepen.io/anon/pen/mAeLq 这是一个工作示例: http : //codepen.io/anon/pen/mAeLq

EDIT: I have also noticed that you have missed this link : 编辑:我也注意到您错过了此链接:

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

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

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