2

我正在尝试将我的地图放在自定义信息框的中心。相反,我正在平移到一个完全不同的地方,远离我的地图标记。这是我的代码:

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);

平移到地图上某个点的更好方法是什么?

4

1 回答 1

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); 
于 2013-05-06T15:21:39.643 回答