2012-05-05 28 views
1

當我將Google地圖用作匿名用戶時,當我找到一家公司正在爲其構建網站時,Google會爲我顯示某種類型的該地點的默認街景視圖照片。這是相當不錯的,我希望這張照片也出現在我準備使用API​​3的自定義InfoWindow中。有沒有一種方法,或者我應該嗅探並使用其源路徑?GoogleMaps:自定義InfoWindow中的默認街景圖像

回答

1

您可以嵌入這樣的街道視圖全景,或在信息窗口的內容嵌入畫面捕獲圖像(<img src="...">),你也可以設置標誌visible: false

http://jsfiddle.net/sST8z/

<!DOCTYPE html> 
<html> 
    <head> 
    <style type="text/css"> 
     html, body { margin: 0; padding: 0; height: 100% } 
     #map_canvas { margin: 0; padding: 0; width: 500px; height: 300px } 
     #street { margin: 0; padding: 0; width: 150px; height: 150px } 

    </style> 
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
     var map; 
     var mapOptions = { center: new google.maps.LatLng(0.0, 0.0), zoom: 2, 
     mapTypeId: google.maps.MapTypeId.ROADMAP }; 

     function initialize() { 
     map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); 
     street = new google.maps.StreetViewPanorama(document.getElementById("street"), { 

     position: new google.maps.LatLng(40.72982797782924, -73.98622512817383), 
     zoomControl: false, 
     enableCloseButton: false, 
     addressControl: false, 
     panControl: false, 
     linksControl: false 
     }); 


     var infow = new google.maps.InfoWindow({ content: document.getElementById("street") }); 
     var myLatLng = new google.maps.LatLng(40.72982797782924, -73.98622512817383); 
     var marker = new google.maps.Marker({ position: myLatLng, map: map, visible: true }); 

     infow.open(map, marker); 
     map.setCenter(myLatLng); 

     } 
     google.maps.event.addDomListener(window, 'load', initialize); 
    </script> 
    </head> 
    <body> 
    <div id="street"></div> 
    <div id="map_canvas"></div> 

    </body> 
</html> 
+0

謝謝你,你的代碼作品在js小提琴中,所以我接受它,但出於某種原因(XHTML + gmap document.write?)不在我的頁面上。還有一個相關的問題:當我平移街景全景圖以很好地定位它時(因爲默認是非常隨機的),是否有可能捕獲所有參數(傾斜,方位角,距離等)並將它們粘貼到JavaScript中碼? – user776686

+0

我解決了它:google.maps.event.addListener(street,'pov_changed',function(){console.log(street.pov)}); – user776686

+0

看起來像是不可能在信息窗口中同時顯示全景圖和文本內容。 .innerHTML和文本的任何串聯都會產生虛假結果。 – user776686

相關問題