2013-07-14 118 views
1

好像在頁面加載了谷歌地圖的信息框的位置是錯誤的,或者至少錯了,當你有你的地圖高度設定在低於400/380px 例如 http://jsfiddle.net/TbDzG/18/谷歌地圖API v3的信息窗口

var startLocation = new google.maps.LatLng(36.151685,-115.152438); 

function initialize() { 
    var mapOptions = { 
     center: startLocation, 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map-canvas"), 
    mapOptions); 

    var marker = new google.maps.Marker({ 
     position: startLocation, 
     map: map, 
     draggable:true, 
     animation: google.maps.Animation.DROP, 
     title:"Hello World!" 
    }); 
    var infowindow = new google.maps.InfoWindow(); 
infowindow.setContent('some content here'); 
infowindow.open(map, marker); 


} 
google.maps.event.addDomListener(window, 'load', initialize); 

沒有人知道如何把它移動到正確的位置和中心的信息框而不是中心的標記?

回答

5

您不能居中infowindow,因爲marker和infowindow(+ map)的位置相同。

試試這個,當地圖加載的時候,InfoWindow會被打開並且會平移地圖。

var infowindow = new google.maps.InfoWindow(); 
infowindow.setContent('some content here'); 
google.maps.event.addListenerOnce(map, 'idle', function(){infowindow.open(map, marker); }); 

http://jsfiddle.net/iambnz/jAgcz/

+0

謝謝了! – Benn

1

如果打開上點擊信息窗口和觸發標記的點擊地圖上呈現完畢後(在「閒置」事件)後,地圖將移動,信息窗口完全顯示。

var startLocation = new google.maps.LatLng(36.151685,-115.152438); 

function initialize() { 
    var mapOptions = { 
     center: startLocation, 
     zoom: 8, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map-canvas"), 
    mapOptions); 

    var infowindow = new google.maps.InfoWindow(); 
    var marker = new google.maps.Marker({ 
     position: startLocation, 
     map: map, 
     draggable:true, 
     animation: google.maps.Animation.DROP, 
     title:"Hello World!" 
    }); 
    google.maps.event.addListener(marker,'click', function(evt) { 
     infowindow.setContent('some content here'); 
     infowindow.open(map, marker); 
    }); 
    google.maps.event.addListenerOnce(map,'idle',function() { 
     google.maps.event.trigger(marker,'click'); 
    }); 
} 
google.maps.event.addDomListener(window, 'load', initialize); 

http://jsfiddle.net/YWbXE/2/