简体   繁体   English

Google Maps API V3灰色区域

[英]Google Maps API V3 Gray Areas

I installed the Google Maps API V3, but I'm having trouble getting the resize function to work properly. 我安装了Google Maps API V3,但是我无法让调整大小功能正常工作。 I've put the script to display the map in a division that drops down when a link is clicked, however, it shows gray areas on the sides. 我已经把脚本显示在一个分区中,当点击一个链接时它会下降,但是,它会在两侧显示灰色区域。 I've read instances where you have to have the resize function in the script that displays the division, from what I can understand, but I'm having trouble implementing it properly. 我已经阅读了一些实例,你需要在脚本中显示调整大小功能,从我能理解的内容来看,但是我在实现它时遇到了麻烦。

在此输入图像描述

Here's the code that causes the division (class="content") to be revealed: 这是导致除法(class =“content”)的代码:

    $(function() {
$('.action').click(function() {          
    var name = $(this).attr("name");
    var content = $('.content[name=' + name + ']');
    $('.content').not(content).hide('fast');
    content.slideToggle('fast');
});

I have the map inside of a div with the id "map". 我有一个id为“map”的div里面的地图。

  <div class="map">
      <div id="map_canvas""></div>
  </div>

I've been up all night working on other portions of the site and am fairly scatterbrained at the moment. 我已经整晚都在网站的其他部分工作,而且目前相当分散。 sorry if I forgot to post something necessary to resolve this. 对不起,如果我忘记发布必要的东西来解决这个问题。

Thanks in advance, Bc. 在此先感谢,Bc。

You need to manually throw the even resize on the google map. 您需要在谷歌地图上手动抛出偶数调整大小。

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

Reference . 参考

Update 更新

<script type="text/javascript"> 
// Global Variable
var map;

// This is a global Function
function initialize() 
{ 
  // This variable is scoped only for the initialize function,
  // it is not available to other functions scoped globally
  var myOptions = 
  { 
    center: new google.maps.LatLng(-34.397, 150.644), 
    zoom: 8, 
    mapTypeId: google.maps.MapTypeId.ROADMAP 
  };

  // Instead of a function scoped map variable this should be global
  map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

  google.maps.event.trigger(map, 'resize') 
} 
</script>

Then you can change to the following code: 然后您可以更改为以下代码:

$(function() 
{
  $('.action').click(function() 
  {          
    var name = $(this).attr("name");
    var content = $('.content[name=' + name + ']');
    $('.content').not(content).hide('fast');
    // this uses the callback functionality
    // to only throw the trigger after the
    // animation finishes.
    content.slideToggle('fast',
      function() 
      {
        google.maps.event.trigger(map, 'resize');
      });
  });
});

Hey I realized a quick easy fix to this: 嘿,我意识到了一个快速简单的解决方法:

function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(42.365885, -71.258658),
        zoom: 16,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
    google.maps.event.trigger(map,'resize');
}

$(document).on("pageshow", "#map", function () {
    initialize();
});

with the page div called "map" and the map div called "map-canvas". 使用名为“map”的页面div和名为“map-canvas”的map div。

What this seems to do is initialize the map when the page is shown. 这似乎是在显示页面时初始化地图。 THis makes your app slower by loading the map when the user opens it, but it avoids errors caused by the dom and whatnot. 这可以通过在用户打开时加载地图来降低您的应用程序速度,但它可以避免由dom和诸如此类引起的错误。 This totally fixes the cornered map/ gray areas problem on my phonegap+jquery mobile + google map app! 这完全修复了我的phonegap + jquery mobile + google地图应用程序中的角落地图/灰色区域问题!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM