gpt4 book ai didi

javascript - 标签未添加到 Google map 标记

转载 作者:行者123 更新时间:2023-11-30 15:02:07 24 4
gpt4 key购买 nike

在我的代码中,我加载 map ,然后在搜索完成后填充表格,然后 map 使用该数据绘制标记。无论我如何尝试,我都无法让标记带有标签。

 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、x y 坐标和标记信息的数据表中提取数据,如下所示。

   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;
}

无论我怎么尝试,某种标签永远都行不通。目前,除了标签之外,我的 map 以我想要的方式工作。希望这是一个简单的修复,不需要过多地重写我现有的代码。我该怎么做才能获得每个图标的标签或者我缺少什么?最好我希望更改在 api 端而不是第 3 方 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

希望对您有所帮助。

关于javascript - 标签未添加到 Google map 标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46371996/

24 4 0