GoogleMapsJavaScriptAPI如何在infobox上集中地图

GoogleMapsJavaScriptAPI如何在infobox上集中地图,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,如果我在谷歌地图上有一个信息框,我如何使信息框在地图上居中显示?我指定此选项以使地图在标记上居中。但在地图标记旁边有一个宽度和高度可变的richmarker框。我希望信息框显示在地图的中心 var lat_lon = new google.maps.LatLng(latitude, longitude); var myOptions = { zoom: 4, center: lat_lon, mapTypeId: google.ma

如果我在谷歌地图上有一个信息框,我如何使信息框在地图上居中显示?我指定此选项以使地图在标记上居中。但在地图标记旁边有一个宽度和高度可变的richmarker框。我希望信息框显示在地图的中心

    var lat_lon = new google.maps.LatLng(latitude, longitude);
    var myOptions = {
        zoom: 4,
        center: lat_lon,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
    };

    map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

    var marker = new google.maps.Marker({
        position: lat_lon,
        map: map,
        title: place,
        icon: 'googlemaps/church3.png',
        clickable: true,
    });

    var mappics_dir = "mappics/";
    var picture_img = "";
    if ( picture != undefined && picture != "" ) {
        picture_img = '<div><img src="'+mappics_dir+picture+'" style="width: auto; height: 100px; min-width: 90px;"/></div>'; 
    }

    marker_info = new RichMarker({
        position: lat_lon,
        map: map,
        draggable: true,
        content: '<div class="channel_marker">' + picture_img + '<div style="width: auto;">'+place+'</div></div>',
        flat: true,
        anchor: RichMarkerPosition.TOP_LEFT,
    });
var lat_lon=new google.maps.LatLng(纬度、经度);
变量myOptions={
缩放:4,
中心:拉图隆,
mapTypeId:google.maps.mapTypeId.ROADMAP,
};
map=new google.maps.map(document.getElementById('map\u canvas'),myOptions);
var marker=new google.maps.marker({
位置:lat_lon,
地图:地图,
标题:地点,
图标:“谷歌地图/church3.png”,
可点击:正确,
});
var mappics_dir=“mappics/”;
var picture_img=“”;
if(picture!=未定义&&picture!=“”){
图片_img=“”;
}
marker_info=新的RichMarker({
位置:lat_lon,
地图:地图,
真的,
内容:''+picture\u img+''+place+'',
平:是的,
主播:RichMarkerPosition.TOP_左上角,
});
richmarker锚定在地图标记上。我想告诉GoogleMapsAPI在地图的中心显示richmarker。谢谢

map.setCenter(lat_lon) 
…将以位置为中心。如果你想以RichMarker为中心,你必须做一些数学计算,得到RichMarker的ContainerPixel或DivPixel中心,然后使用

MapCanvasProjection.fromContainerPixelToLatLong(pixel:Point) or MapCanvasProjection.fromDivPixelToLatLng(pixel:Point) to center on that using map.setCenter(MapCanvasProjection.fromDivPixelToLatLng(pixel:Point)), for example.

听起来是正确的答案。但是当我试图用该代码设置中心时,maps api出错了
var overlay=new google.maps.OverlayView();overlay.draw=函数(){};覆盖.setMap(map);var map_pixel=新的google.maps.Point(200200);var pixelLatLng=overlay.getProjection().fromContainerPixelToLatLng(映射像素);地图设置中心(像素化)只使用map.getProjection()怎么样?您确定该点对容器有效吗?