2014-03-01 36 views
1

我正在使用jQuery選項卡實現Google Map,但沒有正確顯示。
帶有jQuery選項卡的Google Map API

我試過這段代碼來重新調整標籤ID的地圖onclick。

<script type="text/javascript"> 
    jQuery.noConflict(); 
    jQuery(document).ready(function() { 
     jQuery("#tab6").click(function() { 
      google.maps.event.trigger('location-canvas', 'resize'); 
      map.setCenter(bounds.getCenter()); 
      map.setZoom(16); 
     }); 
    }); 
</script> 

但沒有工作。

我使用此選項卡腳本:Simple jQuery Responsive Tabs Interface Plugin - jQueryTab

而且我的jsfiddle是:Code

我會很高興如果你指導我,幫助我解決這個問題。

謝謝。

回答

2
  1. 你觸發'location-canvas'事件,什麼是隻有一個字符串,則必須提供google.maps.Map -instance作爲參數
  2. 觸發調整大小事件的onclick可能還爲時過早,使用的的after - 方法插件。

    after: function(){if($(this).text()==='Google Map'){ 
        //map must be the google.maps.Map-instance and available here 
        center=map.getCenter(); 
        google.maps.event.trigger(map,'resize'); 
        map.setCenter(center);            
    }} 
    

演示:http://jsfiddle.net/doktormolle/xzVpW/

注:map -variable不可用後的方法內。在我修改的小提琴中,我將實例存儲在$('#location-canvas').data

+0

非常感謝您的大力幫助。 :) –

相關問題