javascript - 隐藏 div 中的 Google map

标签 javascript html maps hidden

我有一个包含两个选项卡的页面。第一个标签有照片,第二个标签有谷歌地图。问题是谷歌地图没有完全绘制,因为它位于隐藏的 div 中。所以我使用 onclick() 将 initialize() 函数移动到 map 选项卡的 href。这在您第一次单击它时有效,但是当您返回照片选项卡然后返回 map 选项卡时, map 仅部分绘制。如果您再次单击 map 选项卡,它会完美运行。有什么想法吗?

标签 javascript:

<script type="text/javascript">

$(function () {
    var tabContainers = $('div.tabs > div');

    $('div.tabs ul.tabNavigation a').click(function () {
        tabContainers.hide().filter(this.hash).show();

        $('div.tabs ul.tabNavigation a').removeClass('selected');
        $(this).addClass('selected');

        return false;
    }).filter(':first').click();
});

</script>

谷歌地图 javascript:

<script type="text/javascript">
  function initialize() {
    var latlng = new google.maps.LatLng(<?=$lat ?>, <?=$lng ?>);
    var myOptions = {
      zoom: 15,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"),
        myOptions);

   var marker = new google.maps.Marker({
      position: latlng, 
      map: map, 
      title:"<?=$fulladdress ?>"
  });   
}
</script>

html:

<div class="tabs">
        <ul class="tabNavigation">
            <li><a href="#first">Photos</a></li>
            <li><a href="#map_canvas" onclick="initialize(); return false;">Map</a></li>
        </ul>


        <div id="first"> </div>
      <div id="map_canvas" ></div>

最佳答案

在你需要调整 map 大小之前我已经看到了这个:

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

这是针对 V3 的:

http://code.google.com/p/gmaps-api-issues/issues/detail?id=1448

更多信息:

https://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/251f20b769d116ea/ba3ca54f5e1352a2?pli=1

关于javascript - 隐藏 div 中的 Google map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7084363/

相关文章:

javascript - WebAudio API麦克风分贝阈值/门控(麦克风输入过于敏感)

javascript - 苹果在贪吃蛇游戏中无法正常生成

javascript - 检查 Angular 形式在 Controller 中是否有效

java - 在移动应用程序中高效的本地存储和 map 访问?

c++ - 需要 C++ 使用 map 来跟踪输入文件中的单词的帮助

javascript - 如何在 React Native 中为获取 API 请求创建进度条?

javascript - JQuery 与 getElementbyId - 返回内容的差异

javascript - 如何在 D3/javascripts 中将一列绘制为 x 轴,另一列绘制为 y 轴

javascript - 在下拉 javascript 中显示选定的选项

java - 在java中将map的map转换为map的列表