簡體   English   中英

Google Maps JavaScript API如何在信息框上居中顯示地圖

[英]Google maps javascript API how to center map on infobox

如果我在Google地圖上有一個信息框,如何使該信息框在地圖上居中顯示? 我指定此選項以使地圖在標記上居中。 但是我在地圖標記旁邊有一個寬度和高度可變的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,
    });

richmarker錨定在地圖標記上。 我想告訴Google Maps API在地圖中心顯示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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM