0

这是演示我注意到的问题的代码。

> JSFiddle <

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <style type='text/css'>
    html, body {
        height: 100%;
        margin: 0;
        padding: 0;
    }
    p,h4 {
        margin:0;
    }
    #map-canvas{
        width:425px;
        height:300px;
        margin:1em;
    }
  </style>
</head>
<body>
  <div id="map-canvas"></div>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script type='text/javascript'>//<![CDATA[ 

function initialize() {
    var myLatlng = new google.maps.LatLng(-38.06794990,145.30192430);
    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 style="width:300px;"><H4>Heading</H4><P><B>Address:</B> Community Centre 51L The Strand, Narre Warren South 3805</P></div>';

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

    var marker = new google.maps.Marker({
        position: myLatlng,
        map: map,
        title: 'Food Waste and Organics workshop'
    });
    infowindow.open(map, marker);

    google.maps.event.addListener(marker, 'click', function(event) {
        infowindow.open(map, marker);
    });

}

google.maps.event.addDomListener(window, 'load', initialize);
//]]>  
</script>
</body>
</html>

当信息窗口通过点击事件打开时,它可以正常打开。但是,如果它在窗口加载事件中完成,它不会正确对齐地图区域中的信息窗口,并且信息窗口的顶部被切断。即使增加地图 div 的高度似乎也无济于事。

谢谢,库马尔。

4

1 回答 1

3

Check out Google maps Docs for panTo().

map.panTo(new google.maps.LatLng(lat + your panDownValue, lon));

This is just a quick fix for your question.

JSFIDDLE 1

EDIT: I tried to trigger the marker's "click" event and it is working fine.

google.maps.event.addListenerOnce(map, 'idle', function(){
      google.maps.event.trigger(marker,'click');
 });

idle Event fired when the map becomes idle after panning or zooming.

JSFIDDLE 2

于 2013-05-24T09:15:13.123 回答