0

編輯:聽說谷歌,他們已經證實這是他們的問題。谷歌地圖V3 StreetView不會顯示在第二個setVisible()調用

EDIT2:我在Google的聯繫人告訴我他們已經修復了這個錯誤。

我使用谷歌地圖V3 API有一個麻煩的錯誤。

如果您設置了地圖,切換到街景,關閉街景,然後重新打開,圖像顯示爲空白(儘管控件仍顯示)。如果您點擊控件移動相機,圖像將返回。

這是什麼原因造成的?正如你可以看到下面的代碼非常簡單,我不能認爲我出錯了。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" > 
    <head> 
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> 
    </head> 
    <body> 
    <div id="map" style="width:500px;height:300px"></div> 

    <script type="text/javascript"> 
     var map = new google.maps.Map(document.getElementById('map'), { 
     center: new google.maps.LatLng(37.767063, -122.445724), 
     mapTypeId: google.maps.MapTypeId.ROADMAP, 
     zoom: 15 
     }); 

     var streetView = map.getStreetView(); 
     streetView.setPosition(map.getCenter()); 

     setTimeout(function() { streetView.setVisible(true); }, 1500); 
     setTimeout(function() { streetView.setVisible(false); }, 3000); 
     setTimeout(function() { streetView.setVisible(true); }, 4500); 
    </script> 
    </body> 
</html> 
+0

我已經將這個升級到了我在Google的API聯繫人,如果我瞭解到任何相關的信息,我會回報。 – 2010-07-23 21:25:32

回答

0

我發現了同樣惱人的bug,並開發了一個解決方法,使用更多的div和一點CSS。分配街景視圖#street

<div id="map" style="width:500px;height:300px;display:block"></div> 
<div id="street" style="width:500px;height:300px;display:none"></div> 

添加功能切換的div的可見性:

function toggleStreetView() { 
    var mapDiv = document.getElementById('map'); 
    var streetDiv = document.getElementById('street'); 

    var streetVisible = (streetDiv.style.display == 'block'); 
    if (streetVisible) { 
    // hide streetView, show map 
    streetDiv.display = 'none'; 
    mapDiv.display = 'block'; 
    } else { 
    // vice versa 
    mapDiv.display = 'none'; 
    streetDiv.display = 'block'; 
    streetView.setVisible(true); /* order important, show after div is visible */ 
    }  
} 

也許不是最完美的解決方案 - 但它的工作原理。有了CSS絕對定位和JavaScript框架,我更喜歡jQuery,你可以添加一個很好的淡入淡出效果。