1

我正在用谷歌地图写一个网页,我遇到了一些麻烦;

我有一个包含隐藏 div 的 InfoWindow,我想在单击 infoWindow 中的按钮时显示它。但问题是当我显示隐藏的 div 时,infoWindow 的大小不会自动适应新内容。

你能给出一些建议来解决这个问题吗?非常感谢 :-)

这是我的js:

function redraw() {
    var cmt = $("#bodyContent");
    cmt.show();
}

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

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

var contentString = '<div id="content">'+
                    '<h2 id="firstHeading" class="firstHeading">Uluru</h2>'+
                    '<input type="button" value="Test" onclick="redraw()" />' +
                    '<div id="bodyContent" class="test">'+
                    '<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>'+
                    '</div>'+
                    '</div>';

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

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);
                 });
4

0 回答 0