2013-03-19 27 views
2

我想將我的地圖放在自定義信息框的中心。相反,我正在轉向一個完全不同的地方,遠離我的地圖標記。這裏是我的代碼:Google.maps panTo

var projection = this.getProjection(), 
    centerX = point.x - (125)/2, 
    centerY = point.y - (120)/2, 
    centerPoint = new google.maps.Point(centerX, centerY); 
var latLngOfBoxTop = projection.fromContainerPixelToLatLng(centerPoint); 
this.map.panTo(latLngOfBoxTop); 

什麼是更好的方法來平移到地圖上的一個點?

回答

2

我想通了,從來沒有更新我自己的問題。很簡單:我只是將地圖的中心設置爲標記的位置(我已有的經度和緯度),然後我使用「panBy」,它將像素作爲參數,而不是經度和緯度:

var latlng = this.latlng_, 
     div_height = $('#infobox-wrap-' + markerID).css('height').replace(/px/, ''), 
     infoBoxHalfHeight = 0, 
     halfDivHeight = Math.round(div_height/2); 

    infoBoxHalfHeight = halfDivHeight + 16; //accounts for the infoBox's "pointer" graphic 

    this.map.setCenter(latlng); 
    this.map.panBy(0, infoBoxHalfHeight);