2010-05-22 29 views
3

我正面臨以下問題。 在Google Map上,我想用選項卡添加信息窗口,其中使用GDownloadUrl方法從外部文件加載內容。代碼工作很好,但有兩個問題。 a)我第一次點擊一個標記時,沒有任何瑕疵。我需要點擊兩次以獲取信息框。之後,它工作正常。 b)當我關閉信息框並再次打開時,選項卡會重複。每當我重新打開信息框時,這些選項卡都會重複。因此,如果使用下面的代碼並打開信息框3次,我會得到6個選項卡(信息,照片,信息,照片,信息,照片)。任何想法我在這裏做錯了?谷歌地圖:openInfoWindowTabsHtml + GDownloadUrl(Ajax調用)問題

我也試過用JQuery的$ .get方法,但結果是完全一樣的。

function createREMarker(lat,long,reID) 
{ 
    var reMarker = new GMarker(rePoint,iconRE); 
    GEvent.addListener(reMarker, "click", function() 
    { 
     GDownloadUrl('testcontent.php?reID='+reID+'&what=info', function(data) { 
      content1 = data; 
     }); 
     GDownloadUrl('testcontent.php?reID='+reID+'&what=photos', function(data) { 
      content2 = data; 
     }); 
     tabs.push(new GInfoWindowTab('Info', '<div id="mapOverlayContent" style="width:375px; height:220px; overflow:auto;">'+content1+'</div>')); 
     tabs.push(new GInfoWindowTab('Photos', '<div id="mapOverlayContent" style="width:375px; height:220px; overflow:auto;">'+content2+'</div>')); 
     reMarker.openInfoWindowTabsHtml(tabs); 
    }); 
    return reMarker; 
}; 

回答

3

首先,您正在使用現在正式棄用的API的v2。對於一個網站,我保持我做了以下(這是API的v3和用了jQuery):

function createMarker(point, id, markerOptions) { 
    var marker = new google.maps.Marker(point,markerOptions); 
    var Lat = point.lat(); 
    var Lng = point.lng(); 

    google.maps.Event.addListener(marker, "click", function() { 
     $.ajax({ 
      type: "GET", 
      url: "/data/specific.xml?id=" + id, 
      dataType: "xml", 
      success: function(xml) { 
       var this_marker = $(xml).find('marker'); 
       var name = $(this_marker).attr("name"); 
       details_tab = details_tab + "ID: " + id + "<br />Name: " + name + "<br />"; 
       var infowindow = new google.maps.InfoWindow({ 
        content: details_tab, 
       }); 
       infowindow.open(map, marker); 
      } 
     }); 
    } 
    return marker; 
} 

從我所看到的選項卡中的API v3中不再支持? :(但本實施例中從jQuery用戶界面使用選項卡:

http://gmaps-samples-v3.googlecode.com/svn-history/r78/trunk/infowindow/tabs.html

http://code.google.com/p/gmaps-samples-v3/source/browse/trunk/infowindow/tabs.html?r=78

+0

日Thnx沒有想到使用jquery選項卡作爲一種替代的 – mspir 2010-05-24 10:50:01

+0

FYI:所述實例在IE11打破,它示出了3點而不是製表符。 – 2014-05-07 12:51:20