简体   繁体   English

Google地图-无法在我的样式地图中单击标记

[英]Google Maps - can't click on marker in my styled map

i've been looking for a way to add a 100% width and specific map, that has some styling on and shows the marker for the address. 我一直在寻找一种添加100%宽度和特定地图的方法,该地图具有一些样式并显示地址标记。

i found an example that Google Maps APIs page provides ( https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple ) and applied some styles to it. 我找到了Google Maps APIs页面提供的示例( https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple ),并对其应用了一些样式。 if i get Google's entire code and save it in it's own html file, it works prefect. 如果我获得了Google的完整代码并将其保存在自己的html文件中,那么它将非常完美。 however, when i send this code to my complete page, it won't let me click on the marker! 但是,当我将此代码发送到我的完整页面时,它不会让我单击标记!

this is the address i'm using for testing now: http://uno.ag/contato5.html 这是我现在用于测试的地址: http : //uno.ag/contato5.html

any ideias? 有什么想法吗?

thank you in advance! 先感谢您! ;) ;)

function initialize() {
  var myLatlng = new google.maps.LatLng(-23.582423, -46.641885);
  var mapOptions = {
    zoom: 16,
    center: myLatlng,
    styles: [{featureType:"landscape",stylers:[{saturation:-100},{lightness:65},{visibility:"on"}]},{featureType:"poi",stylers:[{saturation:-100},{lightness:51},{visibility:"simplified"}]},{featureType:"road.highway",stylers:[{saturation:-100},{visibility:"simplified"}]},{featureType:"road.arterial",stylers:[{saturation:-100},{lightness:30},{visibility:"on"}]},{featureType:"road.local",stylers:[{saturation:-100},{lightness:40},{visibility:"on"}]},{featureType:"transit",stylers:[{saturation:-100},{visibility:"simplified"}]},{featureType:"administrative.province",stylers:[{visibility:"off"}]/**/},{featureType:"administrative.locality",stylers:[{visibility:"off"}]},{featureType:"administrative.neighborhood",stylers:[{visibility:"on"}]/**/},{featureType:"water",elementType:"labels",stylers:[{visibility:"on"},{lightness:-25},{saturation:-100}]},{featureType:"water",elementType:"geometry",stylers:[{hue:"#ffff00"},{lightness:-25},{saturation:-97}]}]
  };

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

  var contentString = '<div id="content" style="margin-left:15px;margin-top:5px;margin-bottom:15px;margin-right:5px;">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<br /><br /><img src="http://uno.ag/img/logo-top.png"><br /><br />'+
      '<div id="bodyContent">'+
      'Rua Ambrosina de Macedo, 174 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />' +
      'CEP 04013-030 <br /> '+
      '(11) 5579 2062 '+
      '</div>'+
      '</div>';

  var infowindow = new google.maps.InfoWindow({
      content: contentString
  });

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      optimized: true,
      clickable: true,
      title: 'UNO+BRAND'
  });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

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

Your wrapper div is on top of it, making it unlickable. wrapper div位于其顶部,使其难以舔。 You'll notice you can't move the map either, unless you try on the sides. 您会注意到您也无法移动地图,除非您在侧面尝试。 If you F12, and set display:none; 如果您F12,并设置display:none; on div#wrapper you'll see it works just fine. div#wrapper您会看到它正常工作。

On inspecting your code, it seems the problem is you #wrapper container. 在检查代码时,问题似乎出在#wrapper容器上。

<div id="wrapper">
....
</div>

remove it and the marker becomes clickable. 删除它,标记就会变为可点击状态。

Updates: 更新:

I would suggest to remove height: auto !important; 我建议删除height: auto !important; in your styles of #wrapper this will fix the problem rather than setting the z-index and always be careful in using !important . 在您的#wrapper样式中,这将解决问题,而不是设置z-index并且在使用!important务必小心

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

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