簡體   English   中英

標簽未添加到Google Map標記

[英]Label not being added to Google Map marker

在我的代碼上,我加載了地圖,然后在完成搜索后填充了表格,然后地圖使用該數據繪制標記。 無論嘗試什么,我都無法使標記具有標簽。

 var map = null;
 var geocoder = null;
 var point = null;

function DoIt() {
        map = new google.maps.Map(document.getElementById("map"));
        map.setCenter(new GLatLng(28.55074, -82.42082), 10);
        map.addControl(new GLargeMapControl());
        map.addControl(new GScaleControl());
        map.addControl(new GMapTypeControl());

        // Function for handling zooms 
        GEvent.addListener(map, "zoomend", function (oldzoomlevel, zoomlevel) {
            document.getElementById('tbZoomLevel').value = zoomlevel;
        });

        GEvent.addListener(map, "dragend", function (overlay, point) {
            var center = map.getCenter();
            document.getElementById("tbX").value = center.lat();
            document.getElementById("tbY").value = center.lng();
        });
        geocoder = new GClientGeocoder();

        <%= mapVolunteers() %>
    }

然后從數據表中提取數據,返回ID,xy坐標和標記信息,如下所示。

   function createMarker(id, point, info) {
            var marker = new google.maps.Marker(point,{ title: "Id: " + id, label: "test" });
            GEvent.addListener(marker, "click", function () {
                marker.openInfoWindowHtml(info);
            });
            GEvent.addListener(marker, "mouseover", function () {
                try {
                    document.getElementById(marker.idNumber).style.fontSize = '8pt';
                    document.getElementById(marker.idNumber).style.textDecoration = 'underline';
                    document.getElementById(marker.idNumber).style.fontWeight = 'Bold';
                }
                catch (e)
                { }
            });
            GEvent.addListener(marker, "mouseout", function () {
                try {
                    document.getElementById(marker.idNumber).style.fontSize = '8pt';
                    document.getElementById(marker.idNumber).style.textDecoration = '';
                    document.getElementById(marker.idNumber).style.fontWeight = '';
                }
                catch (e)
                { }
            });
            return marker;
        }

不管我嘗試什么,都無法使用標簽。 目前,除了標簽外,我的地圖還可以按照我想要的方式工作。 希望這是一個簡單的修復方法,不需要太多重寫我的現有代碼。 我該怎么做才能獲得帶有每個圖標的標簽,或者我缺少什么? 最好是,我希望更改是在api方面,而不是在第三方js。

我可以看到的一件事是,您實例化標記的方式與平常有所不同。 如果您使用的是Maps Javascript API,通常會這樣做:

var myLatLng = {lat: -25.363, lng: 131.044};
var marker = new google.maps.Marker({
  position: myLatLng,
  map: map,
  title: 'title',
  label: 'A'
});

這是標記的文檔: https : //developers.google.com/maps/documentation/javascript/3.exp/reference#Marker

希望能有所幫助。

暫無
暫無

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

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