简体   繁体   English

将Google Maps InfoWindow设置为超过700像素的宽度

[英]Set google maps InfoWindow to more than 700px width

Content of the InfoWindow that I intend to show is 840px x 660px. 我打算显示的InfoWindow的内容是840px x 660px。 By setting MaxWidth property in the constructor 通过在构造函数中设置MaxWidth属性

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

It sets the window with width of 707px. 它将窗口设置为707px的宽度。 I've manage to overwrite classes for .gm-style-iw and for #content (my content is in div with properly set of width and height), but there are some div tags in between #content div tag and div tag with class .gm-style-iw with width of maximum 707px and height of max 645px (these values I've found by "Inspecting Element" in Chrome). 我已经设法覆盖了.gm-style-iw#content (我的内容在div中具有正确的宽度和高度设置),但是在#content div标签和div标签之间有一些div标签与类.gm-style-iw ,最大宽度为707px,高度最大为645px(这些值是我在Chrome浏览器中的“检查元素”中找到的)。

If I remove entire style (in Chrome Inspect Element) of the leading div tag (which contains at least 7-8 div sub-tags and among them div tag with class .gm-style-iw and #content div tag) and all sub-tags which are without specified class names nor specified id, then the window appears to be fine, BUT I can't manage to set width and height in the class or javascript... can someone help me with this? 如果我删除了前导div标签(包含至少7-8个div子标签,其中包括具有.gm-style-iw#content div标签的div标签)的整个样式(在Chrome Inspect元素中), -没有指定类名或ID的标签,那么窗口似乎很好,但是我无法在类或javascript中设置宽度和高度...有人可以帮我吗?

do not pass 840px pass value like 840 .if you use 840px this you will be getting error like: 不及格840px像通值840 。如果你使用840px这样你会得到错误,如:

identifier starts immediately after numeric literal

you should use this: 您应该使用此:

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

see a small demo: 看一个小演示:

 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> 

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

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