簡體   English   中英

自動在Google地圖上的紅色標記上顯示地址

[英]automatic display address on red marker on Google Maps

如何在不按紅色標記的情況下設置自動顯示地址? 下面粘貼的是我的JavaScript代碼。 拜托,我真的需要您的幫助。 我真的對代碼感到困惑,真的希望你們能幫助我。 非常感謝。

        var map;

        map = new GMaps({
            el: '#gmap2',
            lat: 1.289701,
            lng: 103.812879,
            scrollwheel: false,
            zoom: 18,
            zoomControl: true,
            panControl: true,
            streetViewControl: true,
            mapTypeControl: true,
            overviewMapControl: true,
            clickable: true
        });

        var image = '';
        map.addMarker({
            lat: 1.289701,
            lng: 103.812879,
            icon: image,
            animation: google.maps.Animation.DROP,
            verticalAlign: 'bottom',
            horizontalAlign: 'center',
            backgroundColor: '#d3cfcf',
        });

        var styles =[
            {
                "featureType": "road",
                "stylers": [
                    {"color": "#ffffff"}
                ]
            }, {
                "featureType": "water",
                "stylers": [
                    {"color": "#99b3cc"}
                ]
            }, {
                "featureType": "landscape",
                "stylers": [
                    {"color": "#f2efe9"}
                ]
            }, {
                "elementType": "labels.text.fill",
                "stylers": [
                    {"color": "#d3cfcf"}
                ]
            }, {
                "featureType": "poi",
                "stylers": [
                    {"color": "#ded2ac"}
                ]
            }, {
                "elementType": "labels.text",
                "stylers": [
                    {"saturation": 1},
                    {"weight": 0.1},
                    {"color": "#000000"}
                ]
            }

        ];

        map.addStyle({
            styledMapName: "Styled Map",
            styles: styles,
            mapTypeId: "map_style"
        });

        map.setStyle("map_style");
    }());
}

我從這篇文章中得到了答案,所以沒有我的初衷: Google Maps-api v3 InfoWindow在頁面加載時自動打開

看起來您可以創建一個單獨的方法(在此示例中稱為initialize )。 此方法將創建一個新的infoWindow並在頁面加載時加載它。

var infoWindow = null;
function initialize() 
{
    infoWindow = new google.maps.InfoWindow();
    var windowLatLng = new google.maps.LatLng(43.25,-68.03);
    infoWindow.setOptions({
        content: "<div>This is the html content.</div>",
        position: windowLatLng,
    });
    infoWindow.open(map); 
} // end initialize

google.setOnLoadCallback(initialize);

暫無
暫無

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

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