我打算展示的InfoWindow内容是840 px660 to。通过在构造函数中设置MaxWidth属性
(ex. new google.maps.InfoWindow({ content: some_text, maxWidth: 840});)它设置宽度为707 of的窗口。我已经设法为.gm-style-iw和#content覆盖类(我的内容在div中,具有适当的宽度和高度设置),但是#content div标记和类.gm-style-iw之间有一些div标记,其最大宽度为707 max,高度为max 645 max(这些值是我通过在Chrome中“检查元素”找到的)。
如果我删除前导div标记的整个样式(在Chrome检查元素中)(其中至少包含7-8个div子标记,其中包括带有类.gm-style-iw和#content div标记的div标记)和所有没有指定类名或指定id的子标记,则窗口看起来很好,但我无法在类或javascript.中设置宽度和高度.有人能帮我吗?
发布于 2014-12-24 08:12:08
不要传递840px传递值,就像840.if一样,您使用的是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 km (208 mi) '+
'south west of the nearest large town, Alice Springs; 450 km '+
'(280 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>
https://stackoverflow.com/questions/27633593
复制相似问题