如果我在谷歌地图上有一个信息框,我如何让信息框显示在地图上居中?我指定这个以使地图在标记上居中。但是我在地图标记旁边有一个可变宽度和高度的富标记框。我希望信息框能够在地图上居中显示。
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,
});
富标记锚定在地图标记上。我想告诉谷歌地图api在地图中心显示富有的标记。感谢。
答案 0 :(得分:0)
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.