如何使用google.maps.event.trigger(map,'resize');

时间:2015-05-07 09:12:16

标签: javascript jquery google-maps

我是JS的新手,在调整我的谷歌地图时面临挑战。
我的问题:我的地图只有三分之一在显示,这是因为调整大小的触发器需要实现。
我的问题:我在哪里正确地将下面的触发器代码放在我的脚本中以正确实现它。

非常感谢任何帮助

google.maps.event.trigger(map, 'resize');

  

脚本:

<script type="text/javascript">
var map;
/*use google maps api built-in mechanism to attach dom events*/
google.maps.event.addDomListener(window, "load", function () {

  /*create map*/
  var map = new google.maps.Map(document.getElementById("googleMap"), {
    center: new google.maps.LatLng(51.506477,-0.071741),
    zoom: 16,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  });

  /*create infowindow (which will be used by markers)*/
  var infoWindow = new google.maps.InfoWindow();

  /*marker creater function (acts as a closure for html parameter)*/
  function createMarker(options, html) {
    var marker = new google.maps.Marker(options);
    if (html) {
      google.maps.event.addListener(marker, "click", function () {
        infoWindow.setContent(html);
        infoWindow.open(options.map, this);
      });
    }
    return marker;
  }

  /*add markers to map*/
  var marker0 = createMarker({
    position: new google.maps.LatLng(51.506477,-0.071741),
    map: map,
    icon: "../../account/gallery/1700728/images/marker-red.png"
  }, "<p>Saint Katharine's Way London E1W 1LD, United Kingdom</p>");
});


$(document).ready(function() {
    $('#googleMap').css({'width':'100%','height':'380'});
    google.maps.event.trigger(map, 'resize'); 
});
</script>

0 个答案:

没有答案