javascript - 在 Google 地图中设置标签
问题描述
我用 x 个不同的别针制作了一个谷歌地图。当我将鼠标悬停在图钉上时,我可以看到 html 代码:
['Company a<br>\
Address x, Dk-2750 <br>\
<a href="#">Show way</a>
我尝试设置标题和标签,因此我可以选择将鼠标悬停在图钉上时的文本内容。有谁知道当我将鼠标悬停在图钉上时如何在图钉上设置标签?
<script>
function initMap() {
var center = {lat: 56.2639, lng: 9.5018};
var locations = [
['Company a<br>\
Address x, Dk-2750 <br>\
<a href="#" alt>Show way</a>', 55.730097, 12.375905],
['Company b<br>\
Address y, Dk-6600<br>\
<a href="#">Show way</a>', 55.769726, 12.497519],
['Company c<br>\
Address z, Dk-6950<br>\
<a href="#">Show way</a>', 56.110692, 8.322713],
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: center
});
var infowindow = new google.maps.InfoWindow({});
var marker, count;
for (count = 0; count < locations.length; count++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[count][1], locations[count][2]),
map: map,
title: locations[count][0]
});
google.maps.event.addListener(marker, 'click', (function (marker, count) {
return function () {
infowindow.setContent(locations[count][0]);
infowindow.open(map, marker);
}
})(marker, count));
}
}
</script>
解决方案
我想您应该在 google.maps.event 下方再添加一个事件列表器...您可以尝试google.maps.events.addListener(marker,'hover',function(..){...})
或类似的方法。就像我难过一样,我只是在猜测:)
推荐阅读
- html - Html 视频标签无法加载本地路径
- numpy - np.genfromtxt 在什么情况下会读入空数组
- javascript - 如何将函数对象导出到另一个函数对象 javascript (nuxt)?
- algorithm - 一个基因测序分析的算法问题
- javascript - 为什么选择正确答案后我的分数没有增加?
- javascript - || 如何 操作员工作,为什么不工作呢?
- rust - 匹配Option内的值时如何获取可变变量绑定?
- groovy - 使用 HTTPBuilder 发送原始正文数据
- c++ - 如何删除“所有重复的”值?
- python - Pandas:如何使用其他数据框的列值从具有相同行值的数据框中返回行?