【问题标题】:Set google maps InfoWindow to more than 700px width将谷歌地图信息窗口设置为超过 700px 宽度
【发布时间】:2014-12-24 16:35:28
【问题描述】:

我打算显示的 InfoWindow 的内容是 840px x 660px。通过在构造函数中设置 MaxWidth 属性

(ex. new google.maps.InfoWindow({ content: some_text, maxWidth: 840});)

它设置宽度为 707px 的窗口。 我已经设法覆盖.gm-style-iw#content 的类(我的内容在具有正确设置宽度和高度的div 中),但是#content div 标签和带有@ 类的div 标签之间有一些div 标签987654326@,最大宽度为 707 像素,高度最大为 645 像素(这些值是我在 Chrome 中的“检查元素”中找到的)。

如果我删除了前导 div 标签(其中至少包含 7-8 个 div 子标签,其中包含 .gm-style-iw#content div 标签的 div 标签)的整个样式(在 Chrome Inspect Element 中)和所有没有指定类名也没有指定 id 的子标签,然后窗口看起来很好,但是我无法在类或 javascript 中设置宽度和高度... 有人可以帮我解决这个问题吗?

【问题讨论】:

标签: javascript jquery css infowindow


【解决方案1】:

不要传递840px 传递值,例如840。如果您使用840px,您将收到如下错误:

identifier starts immediately after numeric literal

你应该使用这个:

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

看一个小演示:

function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  };

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

  var contentString = '<div id="content">'+
      '<div id="siteNotice">'+
      '</div>'+
      '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
      '<div id="bodyContent">'+
      '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
      'sandstone rock formation in the southern part of the '+
      'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
      'south west of the nearest large town, Alice Springs; 450&#160;km '+
      '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
      'features of the Uluru - Kata Tjuta National Park. Uluru is '+
      'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
      'Aboriginal people of the area. It has many springs, waterholes, '+
      'rock caves and ancient paintings. Uluru is listed as a World '+
      'Heritage Site.</p>'+
      '<p>Attribution: Uluru, <a href="http://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
      'http://en.wikipedia.org/w/index.php?title=Uluru</a> '+
      '(last visited June 22, 2009).</p>'+
      '</div>'+
      '</div>';

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

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Uluru (Ayers Rock)'
  });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}

google.maps.event.addDomListener(window, 'load', initialize);
   html, body, #map-canvas {
        height: 100%;
        margin: 0px;
        padding: 0px
      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?v=3&sensor=false&libraries=drawing,geometry"></script>
<div id="map-canvas"></div>

【讨论】:

  • 这不是解决方案。请“运行代码剪切”并转到“检查元素”,您可以看到前导 div 的宽度为 707px...我无法上传打印屏幕显示
  • 尝试使用它来设置新的宽度: $("div.gm-style").find('*').each(function(){ console.log($(this).width ());$(this).width(840);});
  • 不,这不是解决方案。我也尝试过类似的方法,但仍然不合适和干净的解决方案......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-04-24
  • 1970-01-01
  • 1970-01-01
  • 2014-01-02
  • 1970-01-01
  • 2016-07-10
相关资源
最近更新 更多