-1
我有一個Google Map,並且使用API v3製作了一個全屏切換按鈕。中心點位於大多數左上角
問題:setCenter()
中心是在地圖的最左上角。其他一切都有效,如果我將座標換成別的東西,它實際上會改變中心點,但出於某種原因將其設置爲左上角。 display:none;
首先使用,但如果按下按鈕,我會調用resize。
什麼可能是錯誤的?
//JS
if(document.getElementById('toggle-map')) {
google.maps.event.addDomListener(document.getElementById('toggle-map'), 'click', function() {
jQuery('.spinner').fadeIn();
jQuery('#map-wrapper').toggleClass('fullscreen');
jQuery('body').toggleClass('locked');
jQuery('.main-wrapper').toggleClass('locked');
map.setZoom(5);
map.setCenter(new google.maps.LatLng(50, 50));
google.maps.event.addListenerOnce(map, 'idle', function() {
google.maps.event.trigger(map, 'resize');
jQuery('.spinner').fadeOut(800);
});
});
}
//CSS
.fullscreen {
display: block !important;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100vh;
z-index: 10;
}
.locked {
position: fixed;
height: 100%;
overflow: hidden;
width: 100%;
z-index: 9999;
top: 0;
}
[Google地圖中心左上角]的可能重複(http://stackoverflow.com/questions/14044758/google-map-centers-at-top-left-corner) – geocodezip
[Google map in左上角](http://stackoverflow.com/questions/30298177/google-map-in-top-corner-left) – geocodezip
@geocodezip我已經找到這些之前詢問和嘗試所有的答案,但它並沒有解決我的問題問題。但是在測試並重新編排我的大部分代碼之後,我設法自己解決了這個問題。 – Solo