本文介绍了谷歌地图v3部分在左上角加载,调整大小事件不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google地图V3部分放在左上角。我尝试了以下方法:


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


  • 重新整理< script> 标记在索引文件中




但是没有一个适合我。如何解决这个问题。是否存在官方的错误和解决方案?

index.html

 <!DOCTYPE html> 
< html lang =en>
< head>
< meta charset =utf-8>
< title> Bootstrap,来自LayoutIt!< / title>
< meta name =viewportcontent =width = device-width,initial-scale = 1.0>
< meta name =descriptioncontent =>
< meta name =authorcontent =>

< link href =stylesheets / bootstrap.min.css =stylesheet>
< link href =stylesheets / bootstrap-responsive.min.css =stylesheet>
< link href =stylesheets / style.css =stylesheet>
< / head>
< body>
< div id =contentbar>
< div id =dashboard-contentclass =contentbar-main>
一些内容
< / div>
< div id =summary-contentclass =contentbar-mainstyle =display:none;>
< div class =container-fluid>
< div class =row-fluid>
< div class =span12>
< div class =row-fluid>
< div class =span7id =sidebarid>
< p>响应式网页设计是一种方法,我经常称之为一种心态,因为当您要做出反应时,您必须改变您的想法。它背后的基本思想是:一个设计来统治它们 - 不是m.domain.com,没有touch.domain.com,没有3个独立的CSS文件,每个设备或每个方向没有7个PSD文件 - 只是domain.com 在台式机,平板电脑和手机上看起来一样。< / p>
< / div>
< div class =span5id =contentbarid>
< div class =row-fluid>
< div class =span12>
< input type =buttonvalue =toggleid =toggle-button>
< div id =map-canvasstyle =width:100%; height:400px;>< / div>
< / div>
< / div>
< div class =row-fluid>
< div class =span12>
< p>响应式网页设计是一种方法,我经常称之为一种心态,因为当您要做出反应时,您必须改变您的想法。它背后的基本思想是:一个设计来统治它们 - 不是m.domain.com,没有touch.domain.com,没有3个独立的CSS文件,每个设备或每个方向没有7个PSD文件 - 只是domain.com 在台式机,平板电脑和手机上看起来一样。< / p>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
< / div>
<! - jQuery脚本 - >
< script type =text / javascriptsrc =javascripts / jquery.min.js>< / script>
< script type =text / javascriptsrc =javascripts / bootstrap.min.js>< / script>
<! - 我的基本脚本文件 - >
< script type =text / javascriptsrc =javascripts / my-script.js>< / script>
<! - Google地图服务器网址 - >
< script type =text / javascriptsrc =https://maps.googleapis.com/maps/api/js?key=AIzaSyAngjBDpe4ep15u5dvlnbZbn1ghA5uISZY&sensor=false>< / script>
< / body>
< / html>

my-script.js

  var map; 
$(document).ready(function(){
google.maps.visualRefresh = true;
initializeMap();
});

//在汇总表中加载地图
函数initializeMap(){
var mapOptions = {
center:new google.maps.LatLng(-34.397,150.644) ,
zoom:8,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById(map-canvas),mapOptions);
google.maps.event.trigger(地图,'resize');
}


解决方案

然后通过等待地图的空闲状态(即完成时),然后调用调整大小来修复它:

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


Google Maps V3 loaded partially on top left corner. I tried the following methods:

  • Add google.maps.event.trigger(map, 'resize'); after map initialization.

  • Rearrange <script> tag in index file

But none works for me. How to solve this issue. Is there an official bug and solution to this issue?

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Bootstrap, from LayoutIt!</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <!-- Bootstrap css files -->
    <link href="stylesheets/bootstrap.min.css" rel="stylesheet">
    <link href="stylesheets/bootstrap-responsive.min.css" rel="stylesheet">
    <link href="stylesheets/style.css" rel="stylesheet">
  </head>
  <body>
    <div id="contentbar">
      <div id="dashboard-content" class="contentbar-main">
        Some Content
      </div>
      <div id="summary-content" class="contentbar-main" style="display:none;">
        <div class="container-fluid">
          <div class="row-fluid">
            <div class="span12">
              <div class="row-fluid">
                <div class="span7" id="sidebarid">
                  <p>Responsive web design is an approach, I often call it a mindset, because you have to change the way you think when you're going responsive. The basic idea behind it is: one design to rule them all - no m.domain.com, no touch.domain.com, no 3 separate CSS files, no 7 PSD files for each device or each orientation - just "domain.com" looking the same on desktop, tablet and phone.</p>
                </div>
                <div class="span5" id="contentbarid">
                  <div class="row-fluid">
                    <div class="span12">
                      <input type="button" value="toggle" id="toggle-button">
                      <div id="map-canvas" style="width:100%;height:400px;"></div>
                    </div>
                  </div>
                  <div class="row-fluid">
                    <div class="span12">
                      <p>Responsive web design is an approach, I often call it a mindset, because you have to change the way you think when you're going responsive. The basic idea behind it is: one design to rule them all - no m.domain.com, no touch.domain.com, no 3 separate CSS files, no 7 PSD files for each device or each orientation - just "domain.com" looking the same on desktop, tablet and phone.</p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <!-- jQuery scripts -->
      <script type="text/javascript" src="javascripts/jquery.min.js"></script>
      <!-- Bootstrap script -->
      <script type="text/javascript" src="javascripts/bootstrap.min.js"></script>
      <!-- My basic script file-->
      <script type="text/javascript" src="javascripts/my-script.js"></script>
      <!--Google Map server url-->
      <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAngjBDpe4ep15u5dvlnbZbn1ghA5uISZY&sensor=false"></script>
    </body>
  </html>

my-script.js

var map;
$(document).ready(function(){
  google.maps.visualRefresh = true;
    initializeMap();
});

//Load Map in Summary Tab
function initializeMap() {
  var mapOptions = {
    center: new google.maps.LatLng(-34.397, 150.644),
    zoom: 8,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
  google.maps.event.trigger(map, 'resize');
}
解决方案

I've had this issue before too and fixed it by waiting for the map's 'idle' state (i.e. when it's finished) and then calling the resize:

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

这篇关于谷歌地图v3部分在左上角加载,调整大小事件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 02:04